Skip to content

fix(cli): show error/hide help for unsupported subcommands (#10760) #12624

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

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

elasticspoon
Copy link
Contributor

@elasticspoon elasticspoon commented Mar 18, 2024

Fixes #10760

The coder CLI quietly accepts any subcommand arguments and silently swallows them.

Currently:

❯ coder | head -n5
coder v2.3.3+e491217

USAGE:
  coder [global-flags] <subcommand>
❯ coder idontexist | head -n5
coder v2.3.3+e491217

USAGE:
  coder [global-flags] <subcommand>

Now help output will not be show when there is an unknown subcommand error. Instead users will be given the command for the help output.

❯ coder idontexist
Encountered an error running "coder", see "coder --help" for more information 
error: unrecognized subcommand "idontexist"
❯ coder iexistbut idontexist
Encountered an error running "coder iexistbut", see "coder iexistbut --help" for more information 
error: unrecognized subcommand "idontexist"

Also this stuff: Encountered an error running "coder iexistbut"... gets written to os.Stdout in prettyErrorFormatter{w: os.Stderr, verbose: r.verbose}, not sure how to test that output.

@cdr-bot cdr-bot bot added the community Pull Requests and issues created by the community. label Mar 18, 2024
@elasticspoon elasticspoon force-pushed the 10760-show-subcommand-errors branch from ef62f90 to 6fa4ef3 Compare March 18, 2024 00:37
…er#10760)

The coder CLI quietly accepts any subcommand arguments and silently swallows them.

Currently:
❯ coder idontexist | head -n5
coder v2.3.3+e491217

USAGE:
  coder [global-flags] <subcommand>

Now help output will not be show but users will be given
the command for the help output.

❯ coder idontexist
Encountered an error running "coder", see "coder --help" for more information
error: unrecognized subcommand "idontexist"

❯ coder iexistbut idontexist
Encountered an error running "coder iexistbut", see "coder iexistbut --help" for more information
unrecognized subcommand "idontexist"
@elasticspoon elasticspoon force-pushed the 10760-show-subcommand-errors branch from 6fa4ef3 to 446a9c0 Compare March 18, 2024 01:36
@elasticspoon elasticspoon marked this pull request as ready for review March 18, 2024 01:37
@kylecarbs kylecarbs requested a review from ammario March 18, 2024 01:38
Copy link
Member

@ammario ammario left a comment

Choose a reason for hiding this comment

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

Nice. Thank you for the contribution.

@ammario ammario merged commit 5011edc into coder:main Mar 18, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community Pull Requests and issues created by the community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show error instead of help when the user uses an unsupported subcommand on the CLI
2 participants