cosmossdk.io/client/v2@v2.0.0-beta.1/autocli/flag/maps/map_uint64_to_value.go (about)

     1  package maps
     2  
     3  import (
     4  	"strconv"
     5  
     6  	"github.com/spf13/pflag"
     7  )
     8  
     9  func newUint64ToString[K uint64, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
    10  	newUint64StringMap := newGenericMapValue(val, p)
    11  	newUint64StringMap.Options = genericMapValueOptions[K, V]{
    12  		genericType: "uint64ToString",
    13  		keyParser: func(s string) (K, error) {
    14  			value, err := strconv.ParseUint(s, 10, 64)
    15  			return K(value), err
    16  		},
    17  		valueParser: func(s string) (V, error) {
    18  			return V(s), nil
    19  		},
    20  	}
    21  	return newUint64StringMap
    22  }
    23  
    24  func Uint64ToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]string, usage string) *map[uint64]string {
    25  	p := make(map[uint64]string)
    26  	flagSet.VarP(newUint64ToString(value, &p), name, shorthand, usage)
    27  	return &p
    28  }
    29  
    30  func newUint64ToInt32[K uint64, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
    31  	newUint64Int32Map := newGenericMapValue(val, p)
    32  	newUint64Int32Map.Options = genericMapValueOptions[K, V]{
    33  		genericType: "uint64ToInt32",
    34  		keyParser: func(s string) (K, error) {
    35  			value, err := strconv.ParseUint(s, 10, 64)
    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 newUint64Int32Map
    44  }
    45  
    46  func Uint64ToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]int32, usage string) *map[uint64]int32 {
    47  	p := make(map[uint64]int32)
    48  	flagSet.VarP(newUint64ToInt32(value, &p), name, shorthand, usage)
    49  	return &p
    50  }
    51  
    52  func newUint64ToInt64[K uint64, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
    53  	newUint64Int64Map := newGenericMapValue(val, p)
    54  	newUint64Int64Map.Options = genericMapValueOptions[K, V]{
    55  		genericType: "uint64ToInt64",
    56  		keyParser: func(s string) (K, error) {
    57  			value, err := strconv.ParseUint(s, 10, 64)
    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 newUint64Int64Map
    66  }
    67  
    68  func Uint64ToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]int64, usage string) *map[uint64]int64 {
    69  	p := make(map[uint64]int64)
    70  	flagSet.VarP(newUint64ToInt64(value, &p), name, shorthand, usage)
    71  	return &p
    72  }
    73  
    74  func newUint64ToUint32[K uint64, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
    75  	newUint64Uint32Map := newGenericMapValue(val, p)
    76  	newUint64Uint32Map.Options = genericMapValueOptions[K, V]{
    77  		genericType: "uint64ToUint32",
    78  		keyParser: func(s string) (K, error) {
    79  			value, err := strconv.ParseUint(s, 10, 64)
    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 newUint64Uint32Map
    88  }
    89  
    90  func Uint64ToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]uint32, usage string) *map[uint64]uint32 {
    91  	p := make(map[uint64]uint32)
    92  	flagSet.VarP(newUint64ToUint32(value, &p), name, shorthand, usage)
    93  	return &p
    94  }
    95  
    96  func newUint64ToUint64[K, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
    97  	newUint64Uint64Map := newGenericMapValue(val, p)
    98  	newUint64Uint64Map.Options = genericMapValueOptions[K, V]{
    99  		genericType: "uint64ToUint64",
   100  		keyParser: func(s string) (K, error) {
   101  			value, err := strconv.ParseUint(s, 10, 64)
   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 newUint64Uint64Map
   110  }
   111  
   112  func Uint64ToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]uint64, usage string) *map[uint64]uint64 {
   113  	p := make(map[uint64]uint64)
   114  	flagSet.VarP(newUint64ToUint64(value, &p), name, shorthand, usage)
   115  	return &p
   116  }
   117  
   118  func newUint64ToBool[K uint64, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
   119  	newUint64BoolMap := newGenericMapValue(val, p)
   120  	newUint64BoolMap.Options = genericMapValueOptions[K, V]{
   121  		genericType: "uint64ToBool",
   122  		keyParser: func(s string) (K, error) {
   123  			value, err := strconv.ParseUint(s, 10, 64)
   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 newUint64BoolMap
   132  }
   133  
   134  func Uint64ToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]bool, usage string) *map[uint64]bool {
   135  	p := make(map[uint64]bool)
   136  	flagSet.VarP(newUint64ToBool(value, &p), name, shorthand, usage)
   137  	return &p
   138  }