Skip to content

fix(cli): mistyped subcommand reports the flag as unknown instead of the command #501

Description

@margaretjgu

A mistyped subcommand followed by flags blames the flag:

elastic stack es serch
-> Error: unknown command: serch          (correct)

elastic stack es serch --index my-index
-> Error: unknown option '--index'        (misleading)

--index is a valid option for the command the user meant. Sending them to look at their flags hides the actual typo.

Commander already handles the bare case correctly, so this is specifically about argument ordering.

Suggested fix: resolve the subcommand before parsing options, so an unrecognized operand is reported as an unknown command regardless of what follows it.

Test plan

  • Test that stack es <typo> --index x errors with unknown command
  • Test that a genuinely unknown option on a valid command still errors with unknown option

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