diff options
| author | Eric Paris <[email protected]> | 2015-09-08 08:49:52 -0500 |
|---|---|---|
| committer | Eric Paris <[email protected]> | 2015-09-08 08:49:52 -0500 |
| commit | f735fdff4ffb34299727eb2e3c9abab588742d41 (patch) | |
| tree | 9476914f0340b527cea03ff04677bd120151dcb4 /flag.go | |
| parent | 8e7dc108ab3a1ab6ce6d922bbaff5657b88e8e49 (diff) | |
| parent | 574bc4cfb94effb3e1bb934f1512c1f1a558000f (diff) | |
Merge pull request #53 from sdomino/feature/private-flags
private flags
Diffstat (limited to 'flag.go')
| -rw-r--r-- | flag.go | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -157,8 +157,9 @@ type Flag struct { Changed bool // If the user set the value (or if left to default) 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 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 + Annotations map[string][]string // used by cobra.Command bash autocomple code } // Value is the interface to the dynamic value stored in a flag. @@ -321,6 +322,17 @@ func (f *FlagSet) MarkShorthandDeprecated(name string, usageMessage string) erro return nil } +// MarkHidden sets a flag to 'hidden' in your program. It will continue to +// function but will not show up in help or usage messages. +func (f *FlagSet) MarkHidden(name string) error { + flag := f.Lookup(name) + if flag == nil { + return fmt.Errorf("flag %q does not exist", name) + } + flag.Hidden = true + return nil +} + // Lookup returns the Flag structure of the named command-line flag, // returning nil if none exists. func Lookup(name string) *Flag { @@ -394,7 +406,7 @@ func (f *FlagSet) FlagUsages() string { x := new(bytes.Buffer) f.VisitAll(func(flag *Flag) { - if len(flag.Deprecated) > 0 { + if len(flag.Deprecated) > 0 || flag.Hidden { return } format := "" |
