| 1 | package cli |
| 2 | |
| 3 | type ( |
| 4 | UintSlice = SliceBase[uint, IntegerConfig, uintValue[uint]] |
| 5 | Uint8Slice = SliceBase[uint8, IntegerConfig, uintValue[uint8]] |
| 6 | Uint16Slice = SliceBase[uint16, IntegerConfig, uintValue[uint16]] |
| 7 | Uint32Slice = SliceBase[uint32, IntegerConfig, uintValue[uint32]] |
| 8 | Uint64Slice = SliceBase[uint64, IntegerConfig, uintValue[uint64]] |
| 9 | UintSliceFlag = FlagBase[[]uint, IntegerConfig, UintSlice] |
| 10 | Uint8SliceFlag = FlagBase[[]uint8, IntegerConfig, Uint8Slice] |
| 11 | Uint16SliceFlag = FlagBase[[]uint16, IntegerConfig, Uint16Slice] |
| 12 | Uint32SliceFlag = FlagBase[[]uint32, IntegerConfig, Uint32Slice] |
| 13 | Uint64SliceFlag = FlagBase[[]uint64, IntegerConfig, Uint64Slice] |
| 14 | ) |
| 15 | |
| 16 | var ( |
| 17 | NewUintSlice = NewSliceBase[uint, IntegerConfig, uintValue[uint]] |
| 18 | NewUint8Slice = NewSliceBase[uint8, IntegerConfig, uintValue[uint8]] |
| 19 | NewUint16Slice = NewSliceBase[uint16, IntegerConfig, uintValue[uint16]] |
| 20 | NewUint32Slice = NewSliceBase[uint32, IntegerConfig, uintValue[uint32]] |
| 21 | NewUint64Slice = NewSliceBase[uint64, IntegerConfig, uintValue[uint64]] |
| 22 | ) |
| 23 | |
| 24 | // UintSlice looks up the value of a local UintSliceFlag, returns |
| 25 | // nil if not found |
| 26 | func (cmd *Command) UintSlice(name string) []uint { |
| 27 | return getUintSlice[uint](cmd, name) |
| 28 | } |
| 29 | |
| 30 | // Uint8Slice looks up the value of a local Uint8SliceFlag, returns |
| 31 | // nil if not found |
| 32 | func (cmd *Command) Uint8Slice(name string) []uint8 { |
| 33 | return getUintSlice[uint8](cmd, name) |
| 34 | } |
| 35 | |
| 36 | // Uint16Slice looks up the value of a local Uint16SliceFlag, returns |
| 37 | // nil if not found |
| 38 | func (cmd *Command) Uint16Slice(name string) []uint16 { |
| 39 | return getUintSlice[uint16](cmd, name) |
| 40 | } |
| 41 | |
| 42 | // Uint32Slice looks up the value of a local Uint32SliceFlag, returns |
| 43 | // nil if not found |
| 44 | func (cmd *Command) Uint32Slice(name string) []uint32 { |
| 45 | return getUintSlice[uint32](cmd, name) |
| 46 | } |
| 47 | |
| 48 | // Uint64Slice looks up the value of a local Uint64SliceFlag, returns |
| 49 | // nil if not found |
| 50 | func (cmd *Command) Uint64Slice(name string) []uint64 { |
| 51 | return getUintSlice[uint64](cmd, name) |
| 52 | } |
| 53 | |
| 54 | func getUintSlice[T uint | uint8 | uint16 | uint32 | uint64](cmd *Command, name string) []T { |
| 55 | if v, ok := cmd.Value(name).([]T); ok { |
| 56 | tracef("uint slice available for flag name %[1]q with value=%[2]v (cmd=%[3]q)", name, v, cmd.Name) |
| 57 | |
| 58 | return v |
| 59 | } |
| 60 | |
| 61 | tracef("uint slice NOT available for flag name %[1]q (cmd=%[2]q)", name, cmd.Name) |
| 62 | return nil |
| 63 | } |