Path: blob/main/vendor/github.com/spf13/pflag/bool_func.go
2875 views
package pflag12// -- func Value3type boolfuncValue func(string) error45func (f boolfuncValue) Set(s string) error { return f(s) }67func (f boolfuncValue) Type() string { return "boolfunc" }89func (f boolfuncValue) String() string { return "" } // same behavior as stdlib 'flag' package1011func (f boolfuncValue) IsBoolFlag() bool { return true }1213// BoolFunc defines a func flag with specified name, callback function and usage string.14//15// The callback function will be called every time "--{name}" (or any form that matches the flag) is parsed16// on the command line.17func (f *FlagSet) BoolFunc(name string, usage string, fn func(string) error) {18f.BoolFuncP(name, "", usage, fn)19}2021// BoolFuncP is like BoolFunc, but accepts a shorthand letter that can be used after a single dash.22func (f *FlagSet) BoolFuncP(name, shorthand string, usage string, fn func(string) error) {23var val Value = boolfuncValue(fn)24flag := f.VarPF(val, name, shorthand, usage)25flag.NoOptDefVal = "true"26}2728// BoolFunc defines a func flag with specified name, callback function and usage string.29//30// The callback function will be called every time "--{name}" (or any form that matches the flag) is parsed31// on the command line.32func BoolFunc(name string, usage string, fn func(string) error) {33CommandLine.BoolFuncP(name, "", usage, fn)34}3536// BoolFuncP is like BoolFunc, but accepts a shorthand letter that can be used after a single dash.37func BoolFuncP(name, shorthand string, usage string, fn func(string) error) {38CommandLine.BoolFuncP(name, shorthand, usage, fn)39}404142