Open shortercode opened 3 years ago
I believe it's possible to workaround this, but requires a chunk of boilerplate
#!/usr/bin/env node
import args from 'args';
args.command('help', 'Display help', () => args.showHelp());
args.option('help', 'Output usage information');
const opts = args.parse(process.argv, { help: false });
if (opts.help) {
args.showHelp();
}
Which would need to be defined on any commands that have subcommands.
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.