From 2d7d8d7c8f35a6bd0ca425c4e3d10f96f8410cd6 Mon Sep 17 00:00:00 2001 From: nateph Date: Tue, 3 Mar 2020 15:26:34 -0700 Subject: [PATCH 1/2] add HideDefaultUsage to Flag type --- flag.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flag.go b/flag.go index 24a5036e..f6d2f867 100644 --- a/flag.go +++ b/flag.go @@ -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 [=""] 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 } @@ -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) From 9e4361a78ec62f14d5fb8f57914993514a28ca9f Mon Sep 17 00:00:00 2001 From: nateph Date: Tue, 3 Mar 2020 15:32:55 -0700 Subject: [PATCH 2/2] add HideDefaultUsage to Flag type --- flag.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flag.go b/flag.go index f6d2f867..3a6990cd 100644 --- a/flag.go +++ b/flag.go @@ -722,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 {