-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbool_list.go
56 lines (46 loc) · 1.45 KB
/
bool_list.go
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"
)
// BoolListValue represents a list of boolean values
type BoolListValue []bool
// BoolListValueAssertion defines an assertion if the Value is a BoolListValue
type BoolListValueAssertion interface {
Value
IsBoolList() bool
}
// NewBoolListValue creates a new BoolListValue
func NewBoolListValue(val []bool, p *[]bool) *BoolListValue {
*p = val
return (*BoolListValue)(p)
}
// Set appends a value
func (b *BoolListValue) Set(val string) error {
v, err := strconv.ParseBool(val)
*b = append(*b, v)
return err
}
// IsBoolList returns true if the Value is a BoolListValue
func (b *BoolListValue) IsBoolList() bool {
return true
}
// BoolListVar defines a boolean list option with a pointer to its value
func (o *OptionParser) BoolListVar(p *[]bool, long string, short rune) {
opt := &Option{long, short, NewBoolListValue([]bool{}, p)}
o.Options = append(o.Options, opt)
}
// BoolListVar defines a boolean list option with a pointer to its value
func BoolListVar(p *[]bool, long string, short rune) {
CommandLine.BoolListVar(p, long, short)
}
// BoolList defines a boolean list option and returns a pointer to its value
func (o *OptionParser) BoolList(long string, short rune) (p *[]bool) {
p = &[]bool{}
o.BoolListVar(p, long, short)
return
}
// BoolList defines a boolean list option and returns a pointer to its value
func BoolList(long string, short rune) (p *[]bool) {
p = CommandLine.BoolList(long, short)
return
}