...
1
16
17 package flag
18
19 import (
20 "fmt"
21 "strconv"
22 )
23
24
25
26 type Tristate int
27
28 const (
29 Unset Tristate = iota
30 True
31 False
32 )
33
34 func (f *Tristate) Default(value bool) {
35 *f = triFromBool(value)
36 }
37
38 func (f Tristate) String() string {
39 b := boolFromTri(f)
40 return fmt.Sprintf("%t", b)
41 }
42
43 func (f Tristate) Value() bool {
44 b := boolFromTri(f)
45 return b
46 }
47
48 func (f *Tristate) Set(value string) error {
49 boolVal, err := strconv.ParseBool(value)
50 if err != nil {
51 return err
52 }
53
54 *f = triFromBool(boolVal)
55 return nil
56 }
57
58 func (f Tristate) Provided() bool {
59 if f != Unset {
60 return true
61 }
62 return false
63 }
64
65 func (f *Tristate) Type() string {
66 return "tristate"
67 }
68
69 func boolFromTri(t Tristate) bool {
70 if t == True {
71 return true
72 } else {
73 return false
74 }
75 }
76
77 func triFromBool(b bool) Tristate {
78 if b {
79 return True
80 } else {
81 return False
82 }
83 }
84
View as plain text