In my CLI when I call node cli.js --help
I get this:
Options:
--help Show help [boolean]
--version Show version number [boolean]
However, when I call node cli.js --h
i get the expected output:
cli.js
Run a set of user flows and save the result
Commands:
cli.js init Setup .user-flowrc.json
...
Options:
--version Show version number [boolean]
-v, --verbose Run with verbose logging [boolean]
...
-h, --help Show help [boolean]
Examples:
init Setup user-flows over prompts
I have tried to add yargs.parse()
Yargs help not displaying all the help options, but it did not change anything.
And I am using .argv
at the end so it should only be called once if I understood Why are commands missing from this yargs script help page?.
Similarly i have read yargs example - yargs/docs/examples.md and added the alias which is why the --h
is working.
There is the code I think is relevant:
export function setupYargs(
commands: YargsCommandObject[],
options: { [key: string]: Options },
config: Record<string, any> = {}
) {
yargs.options(options)
.parserConfiguration({ 'boolean-negation': true })
.recommendCommands()
.config(config)
.example([
['init', 'Setup user-flows over prompts']
])
.help();
commands.forEach((command) => yargs.command(
command.command,
command.description,
command?.builder || (() => {
}),
command.module.handler
));
return yargs.argv;
}
If there is any other section of the code base which may be useful let me know and I will add it to the question.
--- Edit --- I have now narrowed down the issue to the setup of the CLI.
const {collect, persist, assert} = readRcConfig(getRcParam());
(async () => runCli({ commands: commands, options: {
...GLOBAL_OPTIONS
}, config: {...collect, ...persist, ...assert} }))();
Where getRcParam()
gets the path to the configuration:
export function get(): string {
// we don't rely on yargs option normalization features as this can happen before cli bootstrap
const {rcPath, p, ["rc-path"]: rc_path } = argv as any as ArgvOption<any>;
const pathToCfgRc = rcPath || rc_path || p;
return (pathToCfgRc as any as string) || join(DEFAULT_RC_PATH, DEFAULT_RC_NAME);
}
And is passed as a config option.