| 1 | package cliscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.22 `encoding/json`/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.22 fmt/" |
| 6 | "reflectscip-go gomod github.com/golang/go/src go1.22 reflect/" |
| 7 | "sortscip-go gomod github.com/golang/go/src go1.22 sort/" |
| 8 | "stringsscip-go gomod github.com/golang/go/src go1.22 strings/" |
| 9 | ) |
| 10 | |
| 11 | // MapBase wraps map[string]T to satisfy flag.Value |
| 12 | type MapBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#[T any, C any, VC ValueCreatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ValueCreator#[T, C]] struct { |
| 13 | dictscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#dict. *map[string]T |
| 14 | hasBeenSetscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#hasBeenSet. bool |
| 15 | valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#value. Valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Value# |
| 16 | multiValueConfigscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#multiValueConfig. multiValueParsingConfigscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/multiValueParsingConfig# |
| 17 | } |
| 18 | |
| 19 | func (i MapBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#[T, C, VC]) Createscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#Create().(val map[string]T, p *map[string]T, c C) Valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Value# { |
| 20 | *p = map[string]T{} |
| 21 | for k, v := range val { |
| 22 | (*p)[k] = v |
| 23 | } |
| 24 | var t T |
| 25 | np := new(T) |
| 26 | var vc VC |
| 27 | return &MapBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#[T, C, VC]{ |
| 28 | dictscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#dict.: p, |
| 29 | valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#value.: vc.Createscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ValueCreator#Create.(t, np, c), |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | // NewMapBase makes a *MapBase with default values |
| 34 | func NewMapBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/NewMapBase().[T any, C any, VC ValueCreatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ValueCreator#[T, C]](defaults map[string]T) *MapBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#[T, C, VC] { |
| 35 | return &MapBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#[T, C, VC]{ |
| 36 | dictscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#dict.: &defaults, |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // configuration of slicing |
| 41 | func (i *MapBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#[T, C, VC]) setMultiValueParsingConfigscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#setMultiValueParsingConfig().(c multiValueParsingConfigscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/multiValueParsingConfig#) { |
| 42 | i.multiValueConfigscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#multiValueConfig. = c |
| 43 | mvc := &i.multiValueConfigscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#multiValueConfig. |
| 44 | tracefscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/tracef().( |
| 45 | "set map parsing config - keyValueSeparator '%s', slice separator '%s', disable separator:%v", |
| 46 | mvc.MapFlagKeyValueSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/multiValueParsingConfig#MapFlagKeyValueSeparator., |
| 47 | mvc.SliceFlagSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/multiValueParsingConfig#SliceFlagSeparator., |
| 48 | mvc.DisableSliceFlagSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/multiValueParsingConfig#DisableSliceFlagSeparator., |
| 49 | ) |
| 50 | } |
| 51 | |
| 52 | // Set parses the value and appends it to the list of values |
| 53 | func (i *MapBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#[T, C, VC]) Setscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#Set().(value string) error { |
| 54 | if !i.hasBeenSetscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#hasBeenSet. { |
| 55 | *i.dictscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#dict. = map[string]T{} |
| 56 | i.hasBeenSetscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#hasBeenSet. = true |
| 57 | } |
| 58 | |
| 59 | if stringsscip-go gomod github.com/golang/go/src go1.22 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.22 strings/HasPrefix().(value, slPfxscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/slPfx.) { |
| 60 | // Deserializing assumes overwrite |
| 61 | _ = jsonscip-go gomod github.com/golang/go/src go1.22 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.22 `encoding/json`/Unmarshal().([]byte(stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Replacescip-go gomod github.com/golang/go/src go1.22 strings/Replace().(value, slPfxscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/slPfx., "", 1)), &i.dictscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#dict.) |
| 62 | i.hasBeenSetscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#hasBeenSet. = true |
| 63 | return nil |
| 64 | } |
| 65 | |
| 66 | mvc := &i.multiValueConfigscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#multiValueConfig. |
| 67 | keyValueSeparator := mvc.MapFlagKeyValueSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/multiValueParsingConfig#MapFlagKeyValueSeparator. |
| 68 | if len(keyValueSeparator) == 0 { |
| 69 | keyValueSeparator = defaultMapFlagKeyValueSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/defaultMapFlagKeyValueSeparator. |
| 70 | } |
| 71 | |
| 72 | tracefscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/tracef().( |
| 73 | "splitting map value '%s', keyValueSeparator '%s', slice separator '%s', disable separator:%v", |
| 74 | value, |
| 75 | keyValueSeparator, |
| 76 | mvc.SliceFlagSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/multiValueParsingConfig#SliceFlagSeparator., |
| 77 | mvc.DisableSliceFlagSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/multiValueParsingConfig#DisableSliceFlagSeparator., |
| 78 | ) |
| 79 | for _, item := range flagSplitMultiValuesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/flagSplitMultiValues().(value, mvc.SliceFlagSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/multiValueParsingConfig#SliceFlagSeparator., mvc.DisableSliceFlagSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/multiValueParsingConfig#DisableSliceFlagSeparator.) { |
| 80 | key, value, ok := stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Cutscip-go gomod github.com/golang/go/src go1.22 strings/Cut().(item, keyValueSeparator) |
| 81 | if !ok { |
| 82 | return fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22 fmt/Errorf().("item %q is missing separator %q", item, keyValueSeparator) |
| 83 | } |
| 84 | if err := i.valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#value..Setscip-go gomod github.com/golang/go/src go1.22 flag/Value#Set().(value); err != nil { |
| 85 | return err |
| 86 | } |
| 87 | (*i.dictscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#dict.)[key] = i.valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#value..Getscip-go gomod github.com/golang/go/src go1.22 flag/Getter#Get().().(T) |
| 88 | } |
| 89 | |
| 90 | return nil |
| 91 | } |
| 92 | |
| 93 | // String returns a readable representation of this value (for usage defaults) |
| 94 | func (i *MapBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#[T, C, VC]) Stringscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#String().() string { |
| 95 | v := i.Valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#Value().() |
| 96 | var t T |
| 97 | if reflectscip-go gomod github.com/golang/go/src go1.22 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.22 reflect/TypeOf().(t).Kindscip-go gomod github.com/golang/go/src go1.22 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.22 reflect/.Stringscip-go gomod github.com/golang/go/src go1.22 reflect/String. { |
| 98 | return fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().("%v", v) |
| 99 | } |
| 100 | return fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().("%T{%s}", v, i.ToStringscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#ToString().(v)) |
| 101 | } |
| 102 | |
| 103 | // Serialize allows MapBase to fulfill Serializer |
| 104 | func (i *MapBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#[T, C, VC]) Serializescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#Serialize().() string { |
| 105 | jsonBytes, _ := jsonscip-go gomod github.com/golang/go/src go1.22 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.22 `encoding/json`/Marshal().(i.dictscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#dict.) |
| 106 | return fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().("%s%s", slPfxscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/slPfx., string(jsonBytes)) |
| 107 | } |
| 108 | |
| 109 | // Value returns the mapping of values set by this flag |
| 110 | func (i *MapBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#[T, C, VC]) Valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#Value().() map[string]T { |
| 111 | if i.dictscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#dict. == nil { |
| 112 | return map[string]T{} |
| 113 | } |
| 114 | return *i.dictscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#dict. |
| 115 | } |
| 116 | |
| 117 | // Get returns the mapping of values set by this flag |
| 118 | func (i *MapBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#[T, C, VC]) Getscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#Get().() any { |
| 119 | return *i.dictscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#dict. |
| 120 | } |
| 121 | |
| 122 | func (i MapBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#[T, C, VC]) ToStringscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MapBase#ToString().(t map[string]T) string { |
| 123 | var defaultVals []string |
| 124 | var vc VC |
| 125 | for _, k := range sortedKeysscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/sortedKeys().(t) { |
| 126 | defaultVals = append(defaultVals, k+defaultMapFlagKeyValueSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/defaultMapFlagKeyValueSeparator.+vc.ToStringscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ValueCreator#ToString.(t[k])) |
| 127 | } |
| 128 | return stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Joinscip-go gomod github.com/golang/go/src go1.22 strings/Join().(defaultVals, ", ") |
| 129 | } |
| 130 | |
| 131 | func sortedKeysscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/sortedKeys().[T any](dict map[string]T) []string { |
| 132 | keys := make([]string, 0, len(dict)) |
| 133 | for k := range dict { |
| 134 | keys = append(keys, k) |
| 135 | } |
| 136 | sortscip-go gomod github.com/golang/go/src go1.22 sort/.Stringsscip-go gomod github.com/golang/go/src go1.22 sort/Strings().(keys) |
| 137 | return keys |
| 138 | } |