Path: blob/main/vendor/github.com/spf13/pflag/func.go
2875 views
package pflag12// -- func Value3type funcValue func(string) error45func (f funcValue) Set(s string) error { return f(s) }67func (f funcValue) Type() string { return "func" }89func (f funcValue) String() string { return "" } // same behavior as stdlib 'flag' package1011// Func defines a func flag with specified name, callback function and usage string.12//13// The callback function will be called every time "--{name}={value}" (or equivalent) is14// parsed on the command line, with "{value}" as an argument.15func (f *FlagSet) Func(name string, usage string, fn func(string) error) {16f.FuncP(name, "", usage, fn)17}1819// FuncP is like Func, but accepts a shorthand letter that can be used after a single dash.20func (f *FlagSet) FuncP(name string, shorthand string, usage string, fn func(string) error) {21var val Value = funcValue(fn)22f.VarP(val, name, shorthand, usage)23}2425// Func defines a func flag with specified name, callback function and usage string.26//27// The callback function will be called every time "--{name}={value}" (or equivalent) is28// parsed on the command line, with "{value}" as an argument.29func Func(name string, usage string, fn func(string) error) {30CommandLine.FuncP(name, "", usage, fn)31}3233// FuncP is like Func, but accepts a shorthand letter that can be used after a single dash.34func FuncP(name, shorthand string, usage string, fn func(string) error) {35CommandLine.FuncP(name, shorthand, usage, fn)36}373839