-
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
When persistent flag is shadowed, help text does not show shadowing flag #1651
Comments
This problem was reported in I've traced the problem to https://github.com/spf13/cobra/blob/master/command.go#L1502-L1506 where we determine the list of local flags for the help by checking if a flag is not part of the parent. That approach gives priority to persistent flag instead of to local flags. |
The Cobra project currently lacks enough contributors to adequately respond to all issues. This bot triages issues and PRs according to the following rules:
|
Still good |
The Cobra project currently lacks enough contributors to adequately respond to all issues. This bot triages issues and PRs according to the following rules:
|
Still an issue. |
/assign |
This fixes a bug where a child flag that shadows (has the same name as) a parent persistent flag would not be shown in the child command's help output and the parent flag would be shown instead under the global flags section. This change makes the help output consistent with the observed behavior during execution, where the child flag is the one that is actually used. Fixes spf13/cobra#1651 Merge spf13/cobra#1776
If I declare a flag
--flag
on the root command then declare the same local flag on a sub command, the local flag shadows the persistent one. This seems reasonable. However the help command does not respect this and gives priority to persistent flags.Here is a program to illustrate:
First we check what happens to the flag behaviour:
This seems right: the more specialized flag takes precedence.
I don't know if this is just by chance in how pflag behaves. I wasn't aware this was possible.
The problem now, is that the help does not respect this behaviour:
The text was updated successfully, but these errors were encountered: