Skip to content

fix(cli): report mistyped subcommand before options - #504

Open
vianmangal wants to merge 3 commits into
elastic:mainfrom
vianmangal:agent/fix-unknown-subcommand-error
Open

fix(cli): report mistyped subcommand before options#504
vianmangal wants to merge 3 commits into
elastic:mainfrom
vianmangal:agent/fix-unknown-subcommand-error

Conversation

@vianmangal

Copy link
Copy Markdown

Summary

  • defer group-level unknown option validation until Commander resolves a child command
  • report a mistyped subcommand before any options that follow it
  • preserve unknown-option errors for valid leaf commands and groups without a subcommand

Why

Command groups validated unknown options before their default action could identify an invalid subcommand. As a result, elastic stack es serch --index my-index reported --index as unknown instead of identifying the serch typo.

Testing

  • npm test
  • npm run test:lint
  • npm run test:spdx
  • npm run test:notice
  • manually verified mistyped-subcommand, valid-command/invalid-option, and group/invalid-option cases

Closes #501

@vianmangal
vianmangal marked this pull request as ready for review August 6, 2026 11:34
Comment thread src/factory-core.ts Outdated
Comment thread test/cli.test.ts Outdated

@margaretjgu margaretjgu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See inline comments.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants