Skip to content
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

Output usage hint for both unknown subcommand and unknown flag in the same way #1023

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dgn
Copy link

@dgn dgn commented Jan 29, 2020

Now, when you try to run a Command with an unknown sub-command vs. an unknown flag, you'll get:

$ testcommand asdsa
Error: unknown command "asdsa" for "testcommand"
Run 'testcommand --help' for usage.

$ testcommand --asdsa
Error: unknown flag: --asdsa

$ testcommand -asdsa
Error: unknown shorthand flag: 'a' in -asdsa

With these changes, you'll get:

$ testcommand asdsa
Error: unknown command "asdsa" for "testcommand"
Run 'testcommand --help' for usage.

$ testcommand --asdsa
Error: unknown flag: --asdsa
Run 'testcommand --help' for usage.

$ testcommand -asdsa
Error: unknown shorthand flag: 'a' in -asdsa
Run 'testcommand --help' for usage.

@dgn dgn force-pushed the unknown-subcommand-unknown-flag-consistency branch 2 times, most recently from d94f662 to b040f11 Compare January 29, 2020 09:46
@dgn dgn force-pushed the unknown-subcommand-unknown-flag-consistency branch from b040f11 to 91783a0 Compare January 29, 2020 09:48
@CLAassistant
Copy link

CLA assistant check
All committers have signed the CLA.

@jharshman jharshman added the area/lib Methods and functions that exist in the cobra library and consumed by users label Mar 30, 2020
@github-actions
Copy link

This PR is being marked as stale due to a long period of inactivity

@craigbox
Copy link

Bump!

@virtax
Copy link

virtax commented Sep 11, 2020

@spf13 can you please merge this commit? We need it!

hoshsadiq pushed a commit to zulucmd/zulu that referenced this pull request Dec 31, 2022
Now, when you try to run a Command with an unknown sub-command vs. an unknown flag, you'll get:
```
$ testcommand asdsa
Error: unknown command "asdsa" for "testcommand"
Run 'testcommand --help' for usage.

$ testcommand --asdsa
Error: unknown flag: --asdsa

$ testcommand -asdsa
Error: unknown shorthand flag: 'a' in -asdsa
```

With these changes, you'll get:
```
$ testcommand asdsa
Error: unknown command "asdsa" for "testcommand"
Run 'testcommand --help' for usage.

$ testcommand --asdsa
Error: unknown flag: --asdsa
Run 'testcommand --help' for usage.

$ testcommand -asdsa
Error: unknown shorthand flag: 'a' in -asdsa
Run 'testcommand --help' for usage.
```

Merge spf13/cobra#1023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/lib Methods and functions that exist in the cobra library and consumed by users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants