Skip to content

Using $0 (a default command) as an alias breaks the usage output for nested commands #2291

@bglimepoint

Description

@bglimepoint

We've run into an issue with yargs when using an alias for the default command.

Rather than outputting the correct usage for the subcommand when there's a typo, it instead is outputting the usage for the top level commands, but like they're nested under the subcommand.

We've create a little reproduction - https://github.com/bglimepoint/yargs-alias-help-text-bug-example.

The expected output would be:

$ node index.js test testingtypo

index.js test

parent - test description

Commands:
  index.js test testing   testing description
  index.js test testing2  testing description
  index.js test testing3  testing description

Options:
  --version  Show version number  [boolean]
  --help     Show help  [boolean]

Unknown argument: testingtypo

Which is what we get when we remove the aliases: ['$0'] from one of our subcommands; but when using the default command we get the following bug (afaict) instead:

$ node index.js test testingtypo
index.js test testing

testing description

Commands:
  index.js test test        parent - test description
  index.js test command2    parent - command2 description
  index.js test completion  generate completion definition script

Options:
  --version  Show version number  [boolean]
  --help     Show help  [boolean]

Unknown argument: testingtypo

Notice that the usage there is for the top level things (completion, and then the two fake top level commands), not the usage for the test subcommand.

The repro repo has the buggy version on the master branch, and the "working" version on the no-alias branch (due to the removal of the alias).

Hopefully we're not just doing something silly :-D

Thanks for your time and efforts with yargs :-)

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