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

Add hide default value in help/usage #251

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ type Flag struct {
NoOptDefVal string // default value (as text); if the flag is on the command line without any options
Deprecated string // If this flag is deprecated, this string is the new or now thing to use
Hidden bool // used by cobra.Command to allow flags to be hidden from help/usage text
HideDefaultUsage bool // used to hide [="<default>"] addition in help/usage text if a default is set
ShorthandDeprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use
Annotations map[string][]string // used by cobra.Command bash autocomple code
}
Expand Down Expand Up @@ -696,7 +697,7 @@ func (f *FlagSet) FlagUsagesWrapped(cols int) string {
if varname != "" {
line += " " + varname
}
if flag.NoOptDefVal != "" {
if flag.NoOptDefVal != "" && !flag.HideDefaultUsage {
switch flag.Value.Type() {
case "string":
line += fmt.Sprintf("[=\"%s\"]", flag.NoOptDefVal)
Expand All @@ -721,7 +722,7 @@ func (f *FlagSet) FlagUsagesWrapped(cols int) string {
}

line += usage
if !flag.defaultIsZeroValue() {
if !flag.defaultIsZeroValue() && !flag.HideDefaultUsage {
if flag.Value.Type() == "string" {
line += fmt.Sprintf(" (default %q)", flag.DefValue)
} else {
Expand Down