Path: blob/main/vendor/github.com/spf13/viper/flags.go
2875 views
package viper12import "github.com/spf13/pflag"34// FlagValueSet is an interface that users can implement5// to bind a set of flags to viper.6type FlagValueSet interface {7VisitAll(fn func(FlagValue))8}910// FlagValue is an interface that users can implement11// to bind different flags to viper.12type FlagValue interface {13HasChanged() bool14Name() string15ValueString() string16ValueType() string17}1819// pflagValueSet is a wrapper around *pflag.ValueSet20// that implements FlagValueSet.21type pflagValueSet struct {22flags *pflag.FlagSet23}2425// VisitAll iterates over all *pflag.Flag inside the *pflag.FlagSet.26func (p pflagValueSet) VisitAll(fn func(flag FlagValue)) {27p.flags.VisitAll(func(flag *pflag.Flag) {28fn(pflagValue{flag})29})30}3132// pflagValue is a wrapper around *pflag.flag33// that implements FlagValue.34type pflagValue struct {35flag *pflag.Flag36}3738// HasChanged returns whether the flag has changes or not.39func (p pflagValue) HasChanged() bool {40return p.flag.Changed41}4243// Name returns the name of the flag.44func (p pflagValue) Name() string {45return p.flag.Name46}4748// ValueString returns the value of the flag as a string.49func (p pflagValue) ValueString() string {50return p.flag.Value.String()51}5253// ValueType returns the type of the flag as a string.54func (p pflagValue) ValueType() string {55return p.flag.Value.Type()56}575859