-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathint_list.go
More file actions
56 lines (46 loc) · 1.46 KB
/
int_list.go
File metadata and controls
56 lines (46 loc) · 1.46 KB
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
package optparse
import (
"strconv"
)
// IntListValue represents a list of signed integer values
type IntListValue []int
// IntListValueAssertion defines an assertion if the Value is an IntListValue
type IntListValueAssertion interface {
Value
IsIntList() bool
}
// NewIntListValue creates a new IntListValue
func NewIntListValue(val []int, p *[]int) *IntListValue {
*p = val
return (*IntListValue)(p)
}
// Set appends a value
func (i *IntListValue) Set(val string) error {
v, err := strconv.ParseInt(val, 0, 64)
*i = append(*i, int(v))
return err
}
// IsIntList returns true if the Value is an IntListValue
func (i *IntListValue) IsIntList() bool {
return true
}
// IntListVar defines a signed integer list option with a pointer to its value
func (o *OptionParser) IntListVar(p *[]int, long string, short rune) {
opt := &Option{long, short, NewIntListValue([]int{}, p)}
o.Options = append(o.Options, opt)
}
// IntListVar defines a signed integer list option with a pointer to its value
func IntListVar(p *[]int, long string, short rune) {
CommandLine.IntListVar(p, long, short)
}
// IntList defines a signed integer list option and returns a pointer to its value
func (o *OptionParser) IntList(long string, short rune) (p *[]int) {
p = &[]int{}
o.IntListVar(p, long, short)
return
}
// IntList defines a signed integer list option and returns a pointer to its value
func IntList(long string, short rune) (p *[]int) {
p = CommandLine.IntList(long, short)
return
}