File: flag_uint_slice.go

package info (click to toggle)
golang-github-urfave-cli-v3 3.3.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,676 kB
  • sloc: sh: 26; makefile: 16
file content (63 lines) | stat: -rw-r--r-- 2,344 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cli

type (
	UintSlice       = SliceBase[uint, IntegerConfig, uintValue[uint]]
	Uint8Slice      = SliceBase[uint8, IntegerConfig, uintValue[uint8]]
	Uint16Slice     = SliceBase[uint16, IntegerConfig, uintValue[uint16]]
	Uint32Slice     = SliceBase[uint32, IntegerConfig, uintValue[uint32]]
	Uint64Slice     = SliceBase[uint64, IntegerConfig, uintValue[uint64]]
	UintSliceFlag   = FlagBase[[]uint, IntegerConfig, UintSlice]
	Uint8SliceFlag  = FlagBase[[]uint8, IntegerConfig, Uint8Slice]
	Uint16SliceFlag = FlagBase[[]uint16, IntegerConfig, Uint16Slice]
	Uint32SliceFlag = FlagBase[[]uint32, IntegerConfig, Uint32Slice]
	Uint64SliceFlag = FlagBase[[]uint64, IntegerConfig, Uint64Slice]
)

var (
	NewUintSlice   = NewSliceBase[uint, IntegerConfig, uintValue[uint]]
	NewUint8Slice  = NewSliceBase[uint8, IntegerConfig, uintValue[uint8]]
	NewUint16Slice = NewSliceBase[uint16, IntegerConfig, uintValue[uint16]]
	NewUint32Slice = NewSliceBase[uint32, IntegerConfig, uintValue[uint32]]
	NewUint64Slice = NewSliceBase[uint64, IntegerConfig, uintValue[uint64]]
)

// UintSlice looks up the value of a local UintSliceFlag, returns
// nil if not found
func (cmd *Command) UintSlice(name string) []uint {
	return getUintSlice[uint](cmd, name)
}

// Uint8Slice looks up the value of a local Uint8SliceFlag, returns
// nil if not found
func (cmd *Command) Uint8Slice(name string) []uint8 {
	return getUintSlice[uint8](cmd, name)
}

// Uint16Slice looks up the value of a local Uint16SliceFlag, returns
// nil if not found
func (cmd *Command) Uint16Slice(name string) []uint16 {
	return getUintSlice[uint16](cmd, name)
}

// Uint32Slice looks up the value of a local Uint32SliceFlag, returns
// nil if not found
func (cmd *Command) Uint32Slice(name string) []uint32 {
	return getUintSlice[uint32](cmd, name)
}

// Uint64Slice looks up the value of a local Uint64SliceFlag, returns
// nil if not found
func (cmd *Command) Uint64Slice(name string) []uint64 {
	return getUintSlice[uint64](cmd, name)
}

func getUintSlice[T uint | uint8 | uint16 | uint32 | uint64](cmd *Command, name string) []T {
	if v, ok := cmd.Value(name).([]T); ok {
		tracef("uint slice available for flag name %[1]q with value=%[2]v (cmd=%[3]q)", name, v, cmd.Name)

		return v
	}

	tracef("uint slice NOT available for flag name %[1]q (cmd=%[2]q)", name, cmd.Name)
	return nil
}