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

     1  package maps
     2  
     3  import (
     4  	"strconv"
     5  
     6  	"github.com/spf13/pflag"
     7  )
     8  
     9  func newStringToInt32[K string, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] {
    10  	newStringIntMap := newGenericMapValue(val, p)
    11  	newStringIntMap.Options = genericMapValueOptions[K, V]{
    12  		genericType: "stringToInt32",
    13  		keyParser: func(s string) (K, error) {
    14  			return K(s), nil
    15  		},
    16  		valueParser: func(s string) (V, error) {
    17  			value, err := strconv.ParseInt(s, 10, 32)
    18  			return V(value), err
    19  		},
    20  	}
    21  	return newStringIntMap
    22  }
    23  
    24  func StringToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[string]int32, usage string) *map[string]int32 {
    25  	p := make(map[string]int32)
    26  	flagSet.VarP(newStringToInt32(value, &p), name, shorthand, usage)
    27  	return &p
    28  }