Skip to content

Show help for no command and handle unknown command #883

@wclr

Description

@wclr

I trouble to implement folliwng case:

  1. Show message unknown command if some unknnown command supplied
  2. Show help if no command supplied.

To handle unknown command I use default command *, it works ok

  .command({
    command: '*',
    handler: (argv) => {      
      if (argv._[0]) {
        console.log('Unknown commmand', argv._[0])        
      }
    }
  })
 .demand(1)

But demand(1) here doesn't work in this case so If I supply no command nothing happens at all (it goes to * handler)

I tried to use yargs.showHelp() somewhere in '*' handler or just checking main argv

const argv = yargs...

if (!argv._[0]) {
  yargs.showHelp()
}

but it doesn't show help. All it shows:

Options:
  --help  Show help                                                    [boolean]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions