cosmossdk.io/client/v2@v2.0.0-beta.1/autocli/flag/maps/map_bool_to_value.go (about) 1 package maps 2 3 import ( 4 "strconv" 5 6 "github.com/spf13/pflag" 7 ) 8 9 func newBoolToString[K bool, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] { 10 newBoolStringMap := newGenericMapValue(val, p) 11 newBoolStringMap.Options = genericMapValueOptions[K, V]{ 12 genericType: "boolToString", 13 keyParser: func(s string) (K, error) { 14 value, err := strconv.ParseBool(s) 15 return K(value), err 16 }, 17 valueParser: func(s string) (V, error) { 18 return V(s), nil 19 }, 20 } 21 return newBoolStringMap 22 } 23 24 func BoolToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]string, usage string) *map[bool]string { 25 p := make(map[bool]string) 26 flagSet.VarP(newBoolToString(value, &p), name, shorthand, usage) 27 return &p 28 } 29 30 func newBoolToInt32[K bool, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { 31 newBoolInt32Map := newGenericMapValue(val, p) 32 newBoolInt32Map.Options = genericMapValueOptions[K, V]{ 33 genericType: "boolToInt32", 34 keyParser: func(s string) (K, error) { 35 value, err := strconv.ParseBool(s) 36 return K(value), err 37 }, 38 valueParser: func(s string) (V, error) { 39 value, err := strconv.ParseInt(s, 10, 32) 40 return V(value), err 41 }, 42 } 43 return newBoolInt32Map 44 } 45 46 func BoolToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]int32, usage string) *map[bool]int32 { 47 p := make(map[bool]int32) 48 flagSet.VarP(newBoolToInt32(value, &p), name, shorthand, usage) 49 return &p 50 } 51 52 func newBoolToInt64[K bool, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { 53 newBoolInt64Map := newGenericMapValue(val, p) 54 newBoolInt64Map.Options = genericMapValueOptions[K, V]{ 55 genericType: "boolToInt64", 56 keyParser: func(s string) (K, error) { 57 value, err := strconv.ParseBool(s) 58 return K(value), err 59 }, 60 valueParser: func(s string) (V, error) { 61 value, err := strconv.ParseInt(s, 10, 64) 62 return V(value), err 63 }, 64 } 65 return newBoolInt64Map 66 } 67 68 func BoolToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]int64, usage string) *map[bool]int64 { 69 p := make(map[bool]int64) 70 flagSet.VarP(newBoolToInt64(value, &p), name, shorthand, usage) 71 return &p 72 } 73 74 func newBoolToUint32[K bool, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { 75 newBoolUint32Map := newGenericMapValue(val, p) 76 newBoolUint32Map.Options = genericMapValueOptions[K, V]{ 77 genericType: "boolToUint32", 78 keyParser: func(s string) (K, error) { 79 value, err := strconv.ParseBool(s) 80 return K(value), err 81 }, 82 valueParser: func(s string) (V, error) { 83 value, err := strconv.ParseUint(s, 10, 32) 84 return V(value), err 85 }, 86 } 87 return newBoolUint32Map 88 } 89 90 func BoolToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]uint32, usage string) *map[bool]uint32 { 91 p := make(map[bool]uint32) 92 flagSet.VarP(newBoolToUint32(value, &p), name, shorthand, usage) 93 return &p 94 } 95 96 func newBoolToUint64[K bool, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { 97 newBoolUint64Map := newGenericMapValue(val, p) 98 newBoolUint64Map.Options = genericMapValueOptions[K, V]{ 99 genericType: "boolToUint64", 100 keyParser: func(s string) (K, error) { 101 value, err := strconv.ParseBool(s) 102 return K(value), err 103 }, 104 valueParser: func(s string) (V, error) { 105 value, err := strconv.ParseUint(s, 10, 64) 106 return V(value), err 107 }, 108 } 109 return newBoolUint64Map 110 } 111 112 func BoolToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]uint64, usage string) *map[bool]uint64 { 113 p := make(map[bool]uint64) 114 flagSet.VarP(newBoolToUint64(value, &p), name, shorthand, usage) 115 return &p 116 } 117 118 func newBoolToBool[K, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { 119 newBoolBoolMap := newGenericMapValue(val, p) 120 newBoolBoolMap.Options = genericMapValueOptions[K, V]{ 121 genericType: "boolToBool", 122 keyParser: func(s string) (K, error) { 123 value, err := strconv.ParseBool(s) 124 return K(value), err 125 }, 126 valueParser: func(s string) (V, error) { 127 value, err := strconv.ParseBool(s) 128 return V(value), err 129 }, 130 } 131 return newBoolBoolMap 132 } 133 134 func BoolToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]bool, usage string) *map[bool]bool { 135 p := make(map[bool]bool) 136 flagSet.VarP(newBoolToBool(value, &p), name, shorthand, usage) 137 return &p 138 }