github.com/prysmaticlabs/prysm@v1.4.4/shared/cmd/wrap_flags.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 6 "github.com/urfave/cli/v2" 7 "github.com/urfave/cli/v2/altsrc" 8 ) 9 10 // WrapFlags so that they can be loaded from alternative sources. 11 func WrapFlags(flags []cli.Flag) []cli.Flag { 12 wrapped := make([]cli.Flag, 0, len(flags)) 13 for _, f := range flags { 14 switch t := f.(type) { 15 case *cli.BoolFlag: 16 f = altsrc.NewBoolFlag(t) 17 case *cli.DurationFlag: 18 f = altsrc.NewDurationFlag(t) 19 case *cli.GenericFlag: 20 f = altsrc.NewGenericFlag(t) 21 case *cli.Float64Flag: 22 f = altsrc.NewFloat64Flag(t) 23 case *cli.IntFlag: 24 f = altsrc.NewIntFlag(t) 25 case *cli.StringFlag: 26 f = altsrc.NewStringFlag(t) 27 case *cli.StringSliceFlag: 28 f = altsrc.NewStringSliceFlag(t) 29 case *cli.Uint64Flag: 30 f = altsrc.NewUint64Flag(t) 31 case *cli.UintFlag: 32 f = altsrc.NewUintFlag(t) 33 case *cli.Int64Flag: 34 // Int64Flag does not work. See https://github.com/prysmaticlabs/prysm/issues/6478 35 panic(fmt.Sprintf("unsupported flag type type %T", f)) 36 default: 37 panic(fmt.Sprintf("cannot convert type %T", f)) 38 } 39 wrapped = append(wrapped, f) 40 } 41 return wrapped 42 }