cosmossdk.io/client/v2@v2.0.0-beta.1/autocli/flag/maps/map_uint32_to_value.go (about) 1 package maps 2 3 import ( 4 "strconv" 5 6 "github.com/spf13/pflag" 7 ) 8 9 func newUint32ToString[K uint32, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] { 10 newUint32StringMap := newGenericMapValue(val, p) 11 newUint32StringMap.Options = genericMapValueOptions[K, V]{ 12 genericType: "uint32ToString", 13 keyParser: func(s string) (K, error) { 14 value, err := strconv.ParseUint(s, 10, 32) 15 return K(value), err 16 }, 17 valueParser: func(s string) (V, error) { 18 return V(s), nil 19 }, 20 } 21 return newUint32StringMap 22 } 23 24 func Uint32ToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]string, usage string) *map[uint32]string { 25 p := make(map[uint32]string) 26 flagSet.VarP(newUint32ToString(value, &p), name, shorthand, usage) 27 return &p 28 } 29 30 func newUint32ToInt32[K uint32, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { 31 newUint32Int32Map := newGenericMapValue(val, p) 32 newUint32Int32Map.Options = genericMapValueOptions[K, V]{ 33 genericType: "uint32ToInt32", 34 keyParser: func(s string) (K, error) { 35 value, err := strconv.ParseUint(s, 10, 32) 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 newUint32Int32Map 44 } 45 46 func Uint32ToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]int32, usage string) *map[uint32]int32 { 47 p := make(map[uint32]int32) 48 flagSet.VarP(newUint32ToInt32(value, &p), name, shorthand, usage) 49 return &p 50 } 51 52 func newUint32ToInt64[K uint32, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { 53 newUint32Int64Map := newGenericMapValue(val, p) 54 newUint32Int64Map.Options = genericMapValueOptions[K, V]{ 55 genericType: "uint32ToInt64", 56 keyParser: func(s string) (K, error) { 57 value, err := strconv.ParseUint(s, 10, 32) 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 newUint32Int64Map 66 } 67 68 func Uint32ToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]int64, usage string) *map[uint32]int64 { 69 p := make(map[uint32]int64) 70 flagSet.VarP(newUint32ToInt64(value, &p), name, shorthand, usage) 71 return &p 72 } 73 74 func newUint32ToUint32[K, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { 75 newUint32Uint32Map := newGenericMapValue(val, p) 76 newUint32Uint32Map.Options = genericMapValueOptions[K, V]{ 77 genericType: "uint32ToUint32", 78 keyParser: func(s string) (K, error) { 79 value, err := strconv.ParseUint(s, 10, 32) 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 newUint32Uint32Map 88 } 89 90 func Uint32ToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]uint32, usage string) *map[uint32]uint32 { 91 p := make(map[uint32]uint32) 92 flagSet.VarP(newUint32ToUint32(value, &p), name, shorthand, usage) 93 return &p 94 } 95 96 func newUint32ToUint64[K uint32, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { 97 newUint32Uint64Map := newGenericMapValue(val, p) 98 newUint32Uint64Map.Options = genericMapValueOptions[K, V]{ 99 genericType: "uint32ToUint64", 100 keyParser: func(s string) (K, error) { 101 value, err := strconv.ParseUint(s, 10, 32) 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 newUint32Uint64Map 110 } 111 112 func Uint32ToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]uint64, usage string) *map[uint32]uint64 { 113 p := make(map[uint32]uint64) 114 flagSet.VarP(newUint32ToUint64(value, &p), name, shorthand, usage) 115 return &p 116 } 117 118 func newUint32ToBool[K uint32, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { 119 newUint32BoolMap := newGenericMapValue(val, p) 120 newUint32BoolMap.Options = genericMapValueOptions[K, V]{ 121 genericType: "uint32ToBool", 122 keyParser: func(s string) (K, error) { 123 value, err := strconv.ParseUint(s, 10, 32) 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 newUint32BoolMap 132 } 133 134 func Uint32ToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]bool, usage string) *map[uint32]bool { 135 p := make(map[uint32]bool) 136 flagSet.VarP(newUint32ToBool(value, &p), name, shorthand, usage) 137 return &p 138 }