3 import "github.com/spf13/pflag"
5 // FlagValueSet is an interface that users can implement
6 // to bind a set of flags to viper.
7 type FlagValueSet interface {
8 VisitAll(fn func(FlagValue))
11 // FlagValue is an interface that users can implement
12 // to bind different flags to viper.
13 type FlagValue interface {
20 // pflagValueSet is a wrapper around *pflag.ValueSet
21 // that implements FlagValueSet.
22 type pflagValueSet struct {
26 // VisitAll iterates over all *pflag.Flag inside the *pflag.FlagSet.
27 func (p pflagValueSet) VisitAll(fn func(flag FlagValue)) {
28 p.flags.VisitAll(func(flag *pflag.Flag) {
33 // pflagValue is a wrapper aroung *pflag.flag
34 // that implements FlagValue
35 type pflagValue struct {
39 // HasChanges returns whether the flag has changes or not.
40 func (p pflagValue) HasChanged() bool {
44 // Name returns the name of the flag.
45 func (p pflagValue) Name() string {
49 // ValueString returns the value of the flag as a string.
50 func (p pflagValue) ValueString() string {
51 return p.flag.Value.String()
54 // ValueType returns the type of the flag as a string.
55 func (p pflagValue) ValueType() string {
56 return p.flag.Value.Type()