Skip to content

Default subcommand: help on error displays repeated main command #2247

@xmedeko

Description

@xmedeko

I have a command with subcommands and one of them is default, see

const options = yargs
  .command(['export'], 'Do export', yargs =>
    yargs
      .command(['csv', '*'], 'Export to CSV',
        {
          'value': { demandOption: true }
        })
      .command('html', 'Export to HTML', { 'value': { demandOption: true } })
      .demandCommand(1)
  )
  .command(['import'], 'Do import', { 'value': { demandOption: true } })
  .help().strict(true).demandCommand(1)
  .parse();

Actual

When a user types wrong subcommand, then the help is wrong:

$ node index.js export foo

Export to CSV                                                                     
                                                         
Commands:                                                                         
  index.js export export  Do export
  index.js export import  Do import
...

Expected

When I remove '*', i.e. the default command flag, from the csv command, then the help is OK:

$ node index.js export foo

Do export                                                                       

Commands:
  index.js export csv   Export to CSV
  index.js export html  Export to HTML
...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions