@@ -38,6 +38,7 @@ func countConv(sval string) (interface{}, error) {
38
38
return i , nil
39
39
}
40
40
41
+ // GetCount return the int value of a flag with the given name
41
42
func (f * FlagSet ) GetCount (name string ) (int , error ) {
42
43
val , err := f .getFlagType (name , "count" , countConv )
43
44
if err != nil {
@@ -46,39 +47,51 @@ func (f *FlagSet) GetCount(name string) (int, error) {
46
47
return val .(int ), nil
47
48
}
48
49
50
+ // CountVar defines a count flag with specified name, default value, and usage string.
51
+ // The argument p points to an int variable in which to store the value of the flag.
52
+ // A count flag will add 1 to its value evey time it is found on the command line
49
53
func (f * FlagSet ) CountVar (p * int , name string , usage string ) {
50
54
f .CountVarP (p , name , "" , usage )
51
55
}
52
56
57
+ // CountVarP is like CountVar only take a shorthand for the flag name.
53
58
func (f * FlagSet ) CountVarP (p * int , name , shorthand string , usage string ) {
54
59
flag := f .VarPF (newCountValue (0 , p ), name , shorthand , usage )
55
60
flag .NoOptDefVal = "-1"
56
61
}
57
62
63
+ // CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set
58
64
func CountVar (p * int , name string , usage string ) {
59
65
CommandLine .CountVar (p , name , usage )
60
66
}
61
67
68
+ // CountVarP is like CountVar only take a shorthand for the flag name.
62
69
func CountVarP (p * int , name , shorthand string , usage string ) {
63
70
CommandLine .CountVarP (p , name , shorthand , usage )
64
71
}
65
72
73
+ // Count defines a count flag with specified name, default value, and usage string.
74
+ // The return value is the address of an int variable that stores the value of the flag.
75
+ // A count flag will add 1 to its value evey time it is found on the command line
66
76
func (f * FlagSet ) Count (name string , usage string ) * int {
67
77
p := new (int )
68
78
f .CountVarP (p , name , "" , usage )
69
79
return p
70
80
}
71
81
82
+ // CountP is like Count only takes a shorthand for the flag name.
72
83
func (f * FlagSet ) CountP (name , shorthand string , usage string ) * int {
73
84
p := new (int )
74
85
f .CountVarP (p , name , shorthand , usage )
75
86
return p
76
87
}
77
88
89
+ // Count like Count only the flag is placed on the CommandLine isntead of a given flag set
78
90
func Count (name string , usage string ) * int {
79
91
return CommandLine .CountP (name , "" , usage )
80
92
}
81
93
94
+ // CountP is like Count only takes a shorthand for the flag name.
82
95
func CountP (name , shorthand string , usage string ) * int {
83
96
return CommandLine .CountP (name , shorthand , usage )
84
97
}
0 commit comments