Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
xmedeko opened this issue Oct 11, 2022 · 1 comment
Closed

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

xmedeko opened this issue Oct 11, 2022 · 1 comment

Comments

@xmedeko
Copy link

xmedeko commented Oct 11, 2022

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
...
@bcoe
Copy link
Member

bcoe commented Feb 21, 2023

@xmedeko a fix for this should now be available in yargs@ 17.7.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants