You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to build a CLI app which follows the PROGRAM CATEGORY COMMAND syntax pattern, while testing the help generation I discovered that the help option only ever runs for the primary command. By debugging the library I found this in parse.js
// If default help is allowed, check for itif(this.config.help){this.checkHelp()}
which runs before the subcommand interpretation, causing the application the print the primary command help instead of the subcommand help and never call the subcommand.
Example code
app.js
#!/usr/bin/env node
importargsfrom'args';args.command('sub','Do the subcommand');args.parse(process.argv);
> app --help
Usage: app [options] [command]
Commands:
help Display help
sub Do the subcommand
version Display version
Options:
-h, --help Output usage information
-v, --version Output the version number
> app sub --help
Usage: app [options] [command]
Commands:
help Display help
sub Do the subcommand
version Display version
Options:
-h, --help Output usage information
-v, --version Output the version number
> app sub help
Usage: app sub [command]
Commands:
help Display help
version Display version
Options:
-h, --help Output usage information
-v, --version Output the version number
The help subcommand appears to work correctly, looking at the contents of checkHelp it appears to immediately run help if the option is set. Whereas the sub command is registered before and interpreted later in the subcommand interpretation.
Removing the if (this.optionWasProvided('help')) check from checkHelp and placing it after the subcommand checks in parse would resolve this issue and make the help option consistent with the help subcommand.
The same issue appears to be true for versions as well, but I haven't tested this.
The text was updated successfully, but these errors were encountered:
I'm trying to build a CLI app which follows the
PROGRAM CATEGORY COMMAND
syntax pattern, while testing the help generation I discovered that the help option only ever runs for the primary command. By debugging the library I found this inparse.js
which runs before the subcommand interpretation, causing the application the print the primary command help instead of the subcommand help and never call the subcommand.
Example code
app.js
app-sub.js
Output
The
help
subcommand appears to work correctly, looking at the contents ofcheckHelp
it appears to immediately runhelp
if the option is set. Whereas the sub command is registered before and interpreted later in the subcommand interpretation.Removing the
if (this.optionWasProvided('help'))
check from checkHelp and placing it after the subcommand checks in parse would resolve this issue and make the help option consistent with the help subcommand.The same issue appears to be true for versions as well, but I haven't tested this.
The text was updated successfully, but these errors were encountered: