Fix(issue #631). Remove reflect calls for Hidden field

This commit is contained in:
Naveen Gogineni
2021-03-25 20:45:30 -04:00
committed by Naveen Gogineni
parent 13ded1e7c4
commit df595c0d85
16 changed files with 84 additions and 2 deletions

11
flag.go
View File

@@ -118,6 +118,14 @@ type DocGenerationFlag interface {
GetValue() string
}
// VisibleFlag is an interface that allows to check if a flag is visible
type VisibleFlag interface {
Flag
// IsVisible returns true if the flag is not hidden, otherwise false
IsVisible() bool
}
func flagSet(name string, flags []Flag) (*flag.FlagSet, error) {
set := flag.NewFlagSet(name, flag.ContinueOnError)
@@ -133,8 +141,7 @@ func flagSet(name string, flags []Flag) (*flag.FlagSet, error) {
func visibleFlags(fl []Flag) []Flag {
var visible []Flag
for _, f := range fl {
field := flagValue(f).FieldByName("Hidden")
if !field.IsValid() || !field.Bool() {
if vf, ok := f.(VisibleFlag); ok && vf.IsVisible() {
visible = append(visible, f)
}
}