github.com/prysmaticlabs/prysm@v1.4.4/shared/featureconfig/filter_flags.go (about)

     1  package featureconfig
     2  
     3  import (
     4  	"reflect"
     5  
     6  	"github.com/urfave/cli/v2"
     7  )
     8  
     9  // ActiveFlags returns all of the flags that are not Hidden.
    10  func ActiveFlags(flags []cli.Flag) []cli.Flag {
    11  	visible := make([]cli.Flag, 0, len(flags))
    12  	for _, flag := range flags {
    13  		field := flagValue(flag).FieldByName("Hidden")
    14  		if !field.IsValid() || !field.Bool() {
    15  			visible = append(visible, flag)
    16  		}
    17  	}
    18  	return visible
    19  }
    20  
    21  func flagValue(f cli.Flag) reflect.Value {
    22  	fv := reflect.ValueOf(f)
    23  	for fv.Kind() == reflect.Ptr {
    24  		fv = reflect.Indirect(fv)
    25  	}
    26  	return fv
    27  }