diff options
| author | Eric Paris <[email protected]> | 2018-04-10 17:30:10 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-04-10 17:30:10 -0400 |
| commit | 329ebf1e04800d11a25047832495199d366580f3 (patch) | |
| tree | 0ceb84cd3f4c7c2302d06ad5fc61f57b49696259 /flag.go | |
| parent | 1ce0cc6db4029d97571db82f85092fccedb572ce (diff) | |
Allow Users To Show Deprecated Flags (#163)
They have to explicitly unhide a deprecated flag to keep the current behavior.
Diffstat (limited to 'flag.go')
| -rw-r--r-- | flag.go | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -285,10 +285,10 @@ func (f *FlagSet) HasFlags() bool { } // HasAvailableFlags returns a bool to indicate if the FlagSet has any flags -// definied that are not hidden or deprecated. +// that are not hidden. func (f *FlagSet) HasAvailableFlags() bool { for _, flag := range f.formal { - if !flag.Hidden && len(flag.Deprecated) == 0 { + if !flag.Hidden { return true } } @@ -398,6 +398,7 @@ func (f *FlagSet) MarkDeprecated(name string, usageMessage string) error { return fmt.Errorf("deprecated message for flag %q must be set", name) } flag.Deprecated = usageMessage + flag.Hidden = true return nil } @@ -668,7 +669,7 @@ func (f *FlagSet) FlagUsagesWrapped(cols int) string { maxlen := 0 f.VisitAll(func(flag *Flag) { - if flag.Deprecated != "" || flag.Hidden { + if flag.Hidden { return } @@ -715,6 +716,9 @@ func (f *FlagSet) FlagUsagesWrapped(cols int) string { line += fmt.Sprintf(" (default %s)", flag.DefValue) } } + if len(flag.Deprecated) != 0 { + line += fmt.Sprintf(" (DEPRECATED: %s)", flag.Deprecated) + } lines = append(lines, line) }) |
