Commander.js: about commander -h and help command

Created on 19 Jan 2020  路  5Comments  路  Source: tj/commander.js

First, the cli code as:

const cli = require('commander');
const plugin = require('./commandos/plugin');

cli.
  command('plugin [command] [pluginName]').
  description(DESCRIPTION.plugin).
  action(plugin);

cli.
  command('help').
  description(DESCRIPTION.help).
  action(()=>cli.help());

cli.parse(process.argv);

When I type the command as in terminal:

cli plugin help

it was not run the [plugin] function, I can not get [command] param, it just print help information in the terminal?
it is a bug, right?

bug

Most helpful comment

@shadowspawn
Thank you very much for your timely feedback. I am in no hurry to resolve this issue.

All 5 comments

Investigating... Yes, bug! I think the behaviour got accidentally introduced in #1018 while fixing help for executable subcommands. A single argument of 'help' will display the help. (The comments show I wondered whether the PR would change the behaviour for action based commands, but incorrectly thought it didn't. Drat!)

To reduce the confusion with your sample program, the help is being displayed using internal code and not through your added help command. You can comment that out and will still get help displayed.

This report has been quite useful, as I am rewriting the help behaviour in #1149 and have been trying to understand the old behaviour. My plan is to only add an implicit help command if there are subcommands and no action handler.

@shadowspawn
Thank you very much for your timely feedback. I am in no hurry to resolve this issue.

This is fixed in the published pre-release of Commander v5.0.0 (#1163)

(I am not planning to fix it in v4 unless someone needs it there.)

Commander v5.0.0 has been released.

https://github.com/tj/commander.js/releases/tag/v5.0.0

@shadowspawn fixed! thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

0505gonzalez picture 0505gonzalez  路  3Comments

youurayy picture youurayy  路  5Comments

RoXioTD picture RoXioTD  路  4Comments

mathiasbynens picture mathiasbynens  路  3Comments

aminch picture aminch  路  3Comments