-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Consistency in handling unknown commands/Expose findSuggestions() #870
Comments
Have the same question. Was curious as to the best way to handle this. |
Can you give an example of how you used the workaround? I'd love to take a shot at using it myself. |
This is partially being addressed in #842. |
Thanks a ton for the example! |
This issue is being marked as stale due to a long period of inactivity |
Seems to have been resolved:
|
Hi! Has it been included in a release? From quick testing, I'm able to reproduce the issue on v1.3.0. The example you reference uses subcommands in relation to the root command
to occur. Can you confirm this? |
The default handling of subcommands is to accept arbitrary arguments. If a subcommand is misspelled it prints out the help screen, but if a flag is added then it prints out the error was an unknown flag instead of an unknown command. For example,
root subcommand unknown --flag
returnsERROR: unknown flag: --flag
. Expected behavior should beERROR: unknown command "unknown"
.One workaround I found is to DisableFlagParsing which turns flags into arguments. However, then the help screen is returned rather than the unknown command error. I found adding validation in the run works as a quick fix:
Is there any other way of achieving this desired result? This seems like a function that cobra should support.
Furthermore why is
cmd.findSuggestions()
private where ascmd.SuggestionsFor
public? I think it would be useful to expose findSuggestions so users could simply call a function that returns the full suggestion string instead of manually implementing it like I did above. Not sure if that should be a separate issue, but I think it would be a useful and easy fix.The text was updated successfully, but these errors were encountered: