2020-03-19 21:46:44 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2020-05-31 06:44:34 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"github.com/urfave/cli/v2/altsrc"
|
2020-03-19 21:46:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// WrapFlags so that they can be loaded from alternative sources.
|
|
|
|
func WrapFlags(flags []cli.Flag) []cli.Flag {
|
|
|
|
wrapped := make([]cli.Flag, 0, len(flags))
|
|
|
|
for _, f := range flags {
|
2020-08-10 16:16:45 +00:00
|
|
|
switch t := f.(type) {
|
2020-03-19 21:46:44 +00:00
|
|
|
case *cli.BoolFlag:
|
2020-08-10 16:16:45 +00:00
|
|
|
f = altsrc.NewBoolFlag(t)
|
2020-03-19 21:46:44 +00:00
|
|
|
case *cli.DurationFlag:
|
2020-08-10 16:16:45 +00:00
|
|
|
f = altsrc.NewDurationFlag(t)
|
2020-03-19 21:46:44 +00:00
|
|
|
case *cli.GenericFlag:
|
2020-08-10 16:16:45 +00:00
|
|
|
f = altsrc.NewGenericFlag(t)
|
2020-03-19 21:46:44 +00:00
|
|
|
case *cli.Float64Flag:
|
2020-08-10 16:16:45 +00:00
|
|
|
f = altsrc.NewFloat64Flag(t)
|
2020-03-19 21:46:44 +00:00
|
|
|
case *cli.IntFlag:
|
2020-08-10 16:16:45 +00:00
|
|
|
f = altsrc.NewIntFlag(t)
|
2020-03-19 21:46:44 +00:00
|
|
|
case *cli.StringFlag:
|
2020-08-10 16:16:45 +00:00
|
|
|
f = altsrc.NewStringFlag(t)
|
2020-03-19 21:46:44 +00:00
|
|
|
case *cli.StringSliceFlag:
|
2020-08-10 16:16:45 +00:00
|
|
|
f = altsrc.NewStringSliceFlag(t)
|
2020-03-19 21:46:44 +00:00
|
|
|
case *cli.Uint64Flag:
|
2020-08-10 16:16:45 +00:00
|
|
|
f = altsrc.NewUint64Flag(t)
|
2020-03-19 21:46:44 +00:00
|
|
|
case *cli.UintFlag:
|
2020-08-10 16:16:45 +00:00
|
|
|
f = altsrc.NewUintFlag(t)
|
2020-07-08 08:21:06 +00:00
|
|
|
case *cli.Int64Flag:
|
|
|
|
// Int64Flag does not work. See https://github.com/prysmaticlabs/prysm/issues/6478
|
|
|
|
panic(fmt.Sprintf("unsupported flag type type %T", f))
|
2021-11-30 22:27:03 +00:00
|
|
|
case *cli.IntSliceFlag:
|
|
|
|
f = altsrc.NewIntSliceFlag(t)
|
2020-03-19 21:46:44 +00:00
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("cannot convert type %T", f))
|
|
|
|
}
|
|
|
|
wrapped = append(wrapped, f)
|
|
|
|
}
|
|
|
|
return wrapped
|
|
|
|
}
|