-
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
Allow subcommands to set SilenceUsage
#564
Comments
There is a comment, that "if root command has SilenceUsage flagged, all subcommands should respect it". func (c *Command) ExecuteC() (cmd *Command, err error) {
...
// If root command has SilentUsage flagged,
// all subcommands should respect it
if !cmd.SilenceUsage && !c.SilenceUsage {
c.Println(cmd.UsageString())
}
...
} So it's expected, but I don't think that it's correct behaviour. Why all subcommands must respect it? |
Yes, I did see that comment too. Agree that I don't think it should be the correct behavior. Subcommands should be able to override that flag; same should apply for |
We better fix it in v2.0.0. Thank you for your report! |
The behavior came in with 03aabcd, as part of #169. Note the title:
That is, the idea was to configure things once at the top and have it apply down through the tree. That's convenient, though It's not clear why the general should win over the specific. My guess is that there was a global flag interpreted by a root command that was meant to control the behavior of subcommands. |
The main problem here is, that there is no simple way to detect, if The only way I see here is just to disable the inheritance of this field. It will fix this issue, but it will be inconvenient to set this field explicitly on each command. |
But the advantage here is more explicit and simpler behaviour of cobra and it will be clearer to see if command silences the usage. |
A better way is to add a PersistentSilenceUsage which would be preserved down to subcommands. |
This issue is being marked as stale due to a long period of inactivity |
Currently if the root command has
SilenceUsage
set to true, it appears that I am unable to set this setting tofalse
for child commands that don't want to follow this pattern. Is this expected behavior?The text was updated successfully, but these errors were encountered: