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

     1  package maps
     2  
     3  import (
     4  	"strconv"
     5  
     6  	"github.com/spf13/pflag"
     7  )
     8  
     9  func newInt64ToString[K int64, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
    10  	newInt64StringMap := newGenericMapValue(val, p)
    11  	newInt64StringMap.Options = genericMapValueOptions[K, V]{
    12  		genericType: "int64ToString",
    13  		keyParser: func(s string) (K, error) {
    14  			value, err := strconv.ParseInt(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 newInt64StringMap
    22  }
    23  
    24  func Int64ToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]string, usage string) *map[int64]string {
    25  	p := make(map[int64]string)
    26  	flagSet.VarP(newInt64ToString(value, &p), name, shorthand, usage)
    27  	return &p
    28  }
    29  
    30  func newInt64ToInt32[K int64, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
    31  	newInt64Int32Map := newGenericMapValue(val, p)
    32  	newInt64Int32Map.Options = genericMapValueOptions[K, V]{
    33  		genericType: "int64ToInt32",
    34  		keyParser: func(s string) (K, error) {
    35  			value, err := strconv.ParseInt(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 newInt64Int32Map
    44  }
    45  
    46  func Int64ToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]int32, usage string) *map[int64]int32 {
    47  	p := make(map[int64]int32)
    48  	flagSet.VarP(newInt64ToInt32(value, &p), name, shorthand, usage)
    49  	return &p
    50  }
    51  
    52  func newInt64ToInt64[K, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
    53  	newInt64Int64Map := newGenericMapValue(val, p)
    54  	newInt64Int64Map.Options = genericMapValueOptions[K, V]{
    55  		genericType: "int64ToInt64",
    56  		keyParser: func(s string) (K, error) {
    57  			value, err := strconv.ParseInt(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 newInt64Int64Map
    66  }
    67  
    68  func Int64ToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]int64, usage string) *map[int64]int64 {
    69  	p := make(map[int64]int64)
    70  	flagSet.VarP(newInt64ToInt64(value, &p), name, shorthand, usage)
    71  	return &p
    72  }
    73  
    74  func newInt64ToUint32[K int64, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
    75  	newInt64Uint32Map := newGenericMapValue(val, p)
    76  	newInt64Uint32Map.Options = genericMapValueOptions[K, V]{
    77  		genericType: "int64ToUint32",
    78  		keyParser: func(s string) (K, error) {
    79  			value, err := strconv.ParseInt(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 newInt64Uint32Map
    88  }
    89  
    90  func Int64ToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]uint32, usage string) *map[int64]uint32 {
    91  	p := make(map[int64]uint32)
    92  	flagSet.VarP(newInt64ToUint32(value, &p), name, shorthand, usage)
    93  	return &p
    94  }
    95  
    96  func newInt64ToUint64[K int64, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
    97  	newInt64Uint64Map := newGenericMapValue(val, p)
    98  	newInt64Uint64Map.Options = genericMapValueOptions[K, V]{
    99  		genericType: "int64ToUint64",
   100  		keyParser: func(s string) (K, error) {
   101  			value, err := strconv.ParseInt(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 newInt64Uint64Map
   110  }
   111  
   112  func Int64ToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]uint64, usage string) *map[int64]uint64 {
   113  	p := make(map[int64]uint64)
   114  	flagSet.VarP(newInt64ToUint64(value, &p), name, shorthand, usage)
   115  	return &p
   116  }
   117  
   118  func newInt64ToBool[K int64, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
   119  	newInt64BoolMap := newGenericMapValue(val, p)
   120  	newInt64BoolMap.Options = genericMapValueOptions[K, V]{
   121  		genericType: "int64ToBool",
   122  		keyParser: func(s string) (K, error) {
   123  			value, err := strconv.ParseInt(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 newInt64BoolMap
   132  }
   133  
   134  func Int64ToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]bool, usage string) *map[int64]bool {
   135  	p := make(map[int64]bool)
   136  	flagSet.VarP(newInt64ToBool(value, &p), name, shorthand, usage)
   137  	return &p
   138  }
   139  
   140  func newStringToUint32[K string, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
   141  	newStringUintMap := newGenericMapValue(val, p)
   142  	newStringUintMap.Options = genericMapValueOptions[K, V]{
   143  		genericType: "stringToUint32",
   144  		keyParser: func(s string) (K, error) {
   145  			return K(s), nil
   146  		},
   147  		valueParser: func(s string) (V, error) {
   148  			value, err := strconv.ParseUint(s, 10, 32)
   149  			return V(value), err
   150  		},
   151  	}
   152  	return newStringUintMap
   153  }
   154  
   155  func StringToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[string]uint32, usage string) *map[string]uint32 {
   156  	p := make(map[string]uint32)
   157  	flagSet.VarP(newStringToUint32(value, &p), name, shorthand, usage)
   158  	return &p
   159  }
   160  
   161  func newStringToUint64[K string, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
   162  	newStringUint64Map := newGenericMapValue(val, p)
   163  	newStringUint64Map.Options = genericMapValueOptions[K, V]{
   164  		genericType: "stringToUint64",
   165  		keyParser: func(s string) (K, error) {
   166  			return K(s), nil
   167  		},
   168  		valueParser: func(s string) (V, error) {
   169  			value, err := strconv.ParseUint(s, 10, 64)
   170  			return V(value), err
   171  		},
   172  	}
   173  	return newStringUint64Map
   174  }
   175  
   176  func StringToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[string]uint64, usage string) *map[string]uint64 {
   177  	p := make(map[string]uint64)
   178  	flagSet.VarP(newStringToUint64(value, &p), name, shorthand, usage)
   179  	return &p
   180  }