package pflagimport// -- count Valuetype countValue intfunc newCountValue( int, *int) *countValue { * = return (*countValue)()}func ( *countValue) ( string) error {// "+1" means that no specific value was passed, so incrementif == "+1" { * = countValue(* + 1)returnnil } , := strconv.ParseInt(, 0, 0) * = countValue()return}func ( *countValue) () string {return"count"}func ( *countValue) () string { returnstrconv.Itoa(int(*)) }func countConv( string) (interface{}, error) { , := strconv.Atoi()if != nil {returnnil, }return , nil}// GetCount return the int value of a flag with the given namefunc ( *FlagSet) ( string) (int, error) { , := .getFlagType(, "count", countConv)if != nil {return0, }return .(int), nil}// CountVar defines a count flag with specified name, default value, and usage string.// The argument p points to an int variable in which to store the value of the flag.// A count flag will add 1 to its value every time it is found on the command linefunc ( *FlagSet) ( *int, string, string) { .CountVarP(, , "", )}// CountVarP is like CountVar only take a shorthand for the flag name.func ( *FlagSet) ( *int, , string, string) { := .VarPF(newCountValue(0, ), , , ) .NoOptDefVal = "+1"}// CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag setfunc ( *int, string, string) {CommandLine.CountVar(, , )}// CountVarP is like CountVar only take a shorthand for the flag name.func ( *int, , string, string) {CommandLine.CountVarP(, , , )}// Count defines a count flag with specified name, default value, and usage string.// The return value is the address of an int variable that stores the value of the flag.// A count flag will add 1 to its value every time it is found on the command linefunc ( *FlagSet) ( string, string) *int { := new(int) .CountVarP(, , "", )return}// CountP is like Count only takes a shorthand for the flag name.func ( *FlagSet) (, string, string) *int { := new(int) .CountVarP(, , , )return}// Count defines a count flag with specified name, default value, and usage string.// The return value is the address of an int variable that stores the value of the flag.// A count flag will add 1 to its value evey time it is found on the command linefunc ( string, string) *int {returnCommandLine.CountP(, "", )}// CountP is like Count only takes a shorthand for the flag name.func (, string, string) *int {returnCommandLine.CountP(, , )}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.