-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Need an error when the command is not found in the subcommand #2130
Comments
You can play around with adding the If you search issues you’ll find there have been multiple discussions about this. |
I think the main problem is here: Lines 925 to 927 in e94f6d0
If we could just return another error code instead of In my opinion it must be possible to differentiate between calling Lines 905 to 907 in e94f6d0
|
This requires the caller to change their code to keep the current behavior, which breaks backwards compatibility. If this is important enough, then we could add this as an optional opt-in behavior. |
Ok. What about a further flag in the type Command struct {
// everything else ...
ErrorOnUnknownSubcommand bool
} Default is false - and we would then change the lines in if !c.Runnable() {
if c.ErrorOnUnknownSubcommand {
return ErrUnknownSubcommand
} else {
return flag.ErrHelp
}
} would that be fine? All users who really want this feature can just activate it - and all others will not care. |
That seems reasonable |
hi
Description
When I execute a job on our task center, I need to get the final result of the execution, for example:
myapp job1 args1
When job1 doesn't exist, I can get the error:
Then the task center can be accessed by
echo $?
to get the final execution result.However, when I use a subcommand, I can't get the error.
How to reproduce
For example :
When I execute:
I can get the following prompt without an error.
Expectations
Need to return error
Is there some special consideration here?
https://github.com/spf13/cobra/blob/main/command.go#L1123
The text was updated successfully, but these errors were encountered: