-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbool.go
More file actions
48 lines (39 loc) · 854 Bytes
/
bool.go
File metadata and controls
48 lines (39 loc) · 854 Bytes
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
package rig
import (
"flag"
"strconv"
)
type boolValue bool
func (b boolValue) String() string {
return strconv.FormatBool(bool(b))
}
func (b *boolValue) Set(s string) error {
v, err := strconv.ParseBool(s)
*b = boolValue(v)
return err
}
func (*boolValue) IsBoolFlag() bool {
return true
}
func (*boolValue) New(i interface{}) flag.Value {
return (*boolValue)(i.(*bool))
}
func (b *boolValue) IsNil() bool {
return b == nil
}
// Bool creates a flag for a boolean variable.
func Bool(v *bool, flag, env, usage string) *Flag {
return &Flag{
Value: (*boolValue)(v),
Name: flag,
Env: env,
Usage: usage,
TypeHint: "bool",
}
}
// BoolGenerator is the default boolean generator, to be used with Repeatable for boolean slices.
func BoolGenerator() Generator {
return func() flag.Value {
return new(boolValue)
}
}