| 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 | "stringsscip-go gomod github.com/golang/go/src go1.22 strings/" |
| 8 | ) |
| 9 | |
| 10 | // SliceBase wraps []T to satisfy flag.Value |
| 11 | type SliceBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#[T any, C any, VC ValueCreatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ValueCreator#[T, C]] struct { |
| 12 | slicescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#slice. *[]T |
| 13 | hasBeenSetscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#hasBeenSet. bool |
| 14 | valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#value. Valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Value# |
| 15 | sliceSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#sliceSeparator. string |
| 16 | disableSliceSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#disableSliceSeparator. bool |
| 17 | } |
| 18 | |
| 19 | func (i SliceBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#[T, C, VC]) Createscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#Create().(val []T, p *[]T, c C) Valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Value# { |
| 20 | *p = []T{} |
| 21 | *p = append(*p, val...) |
| 22 | var t T |
| 23 | np := new(T) |
| 24 | var vc VC |
| 25 | return &SliceBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#[T, C, VC]{ |
| 26 | slicescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#slice.: p, |
| 27 | valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#value.: vc.Createscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ValueCreator#Create.(t, np, c), |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // NewSliceBase makes a *SliceBase with default values |
| 32 | func NewSliceBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/NewSliceBase().[T any, C any, VC ValueCreatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ValueCreator#[T, C]](defaults ...T) *SliceBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#[T, C, VC] { |
| 33 | return &SliceBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#[T, C, VC]{ |
| 34 | slicescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#slice.: &defaults, |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | // configuration of slicing |
| 39 | func (i *SliceBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#[T, C, VC]) setMultiValueParsingConfigscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#setMultiValueParsingConfig().(c multiValueParsingConfigscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/multiValueParsingConfig#) { |
| 40 | i.disableSliceSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#disableSliceSeparator. = c.DisableSliceFlagSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/multiValueParsingConfig#DisableSliceFlagSeparator. |
| 41 | i.sliceSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#sliceSeparator. = c.SliceFlagSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/multiValueParsingConfig#SliceFlagSeparator. |
| 42 | tracefscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/tracef().("set slice parsing config - slice separator '%s', disable separator:%v", i.sliceSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#sliceSeparator., i.disableSliceSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#disableSliceSeparator.) |
| 43 | } |
| 44 | |
| 45 | // Set parses the value and appends it to the list of values |
| 46 | func (i *SliceBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#[T, C, VC]) Setscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#Set().(value string) error { |
| 47 | if !i.hasBeenSetscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#hasBeenSet. { |
| 48 | *i.slicescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#slice. = []T{} |
| 49 | i.hasBeenSetscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#hasBeenSet. = true |
| 50 | } |
| 51 | |
| 52 | 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.) { |
| 53 | // Deserializing assumes overwrite |
| 54 | _ = 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.slicescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#slice.) |
| 55 | i.hasBeenSetscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#hasBeenSet. = true |
| 56 | return nil |
| 57 | } |
| 58 | |
| 59 | trimSpace := true |
| 60 | // hack. How do we know if we should trim spaces? |
| 61 | // it makes sense only for string slice flags which have |
| 62 | // an option to not trim spaces. So by default we trim spaces |
| 63 | // otherwise we let the underlying value type handle it. |
| 64 | var t T |
| 65 | 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. { |
| 66 | trimSpace = false |
| 67 | } |
| 68 | |
| 69 | tracefscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/tracef().("splitting slice value '%s', separator '%s', disable separator:%v", value, i.sliceSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#sliceSeparator., i.disableSliceSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#disableSliceSeparator.) |
| 70 | for _, s := range flagSplitMultiValuesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/flagSplitMultiValues().(value, i.sliceSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#sliceSeparator., i.disableSliceSeparatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#disableSliceSeparator.) { |
| 71 | if trimSpace { |
| 72 | s = stringsscip-go gomod github.com/golang/go/src go1.22 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.22 strings/TrimSpace().(s) |
| 73 | } |
| 74 | if err := i.valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#value..Setscip-go gomod github.com/golang/go/src go1.22 flag/Value#Set().(s); err != nil { |
| 75 | return err |
| 76 | } |
| 77 | *i.slicescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#slice. = append(*i.slicescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#slice., i.valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#value..Getscip-go gomod github.com/golang/go/src go1.22 flag/Getter#Get().().(T)) |
| 78 | } |
| 79 | |
| 80 | return nil |
| 81 | } |
| 82 | |
| 83 | // String returns a readable representation of this value (for usage defaults) |
| 84 | func (i *SliceBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#[T, C, VC]) Stringscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#String().() string { |
| 85 | var defaultVals []string |
| 86 | var v VC |
| 87 | for _, s := range *i.slicescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#slice. { |
| 88 | defaultVals = append(defaultVals, v.ToStringscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ValueCreator#ToString.(s)) |
| 89 | } |
| 90 | 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, ", ") |
| 91 | } |
| 92 | |
| 93 | // Serialize allows SliceBase to fulfill Serializer |
| 94 | func (i *SliceBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#[T, C, VC]) Serializescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#Serialize().() string { |
| 95 | 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.slicescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#slice.) |
| 96 | 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)) |
| 97 | } |
| 98 | |
| 99 | // Value returns the slice of values set by this flag |
| 100 | func (i *SliceBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#[T, C, VC]) Valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#Value().() []T { |
| 101 | if i.slicescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#slice. == nil { |
| 102 | return nil |
| 103 | } |
| 104 | return *i.slicescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#slice. |
| 105 | } |
| 106 | |
| 107 | // Get returns the slice of values set by this flag |
| 108 | func (i *SliceBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#[T, C, VC]) Getscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#Get().() any { |
| 109 | return *i.slicescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#slice. |
| 110 | } |
| 111 | |
| 112 | func (i SliceBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#[T, C, VC]) ToStringscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#ToString().(t []T) string { |
| 113 | i.slicescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#slice. = &t |
| 114 | return i.Stringscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/SliceBase#String().() |
| 115 | } |