Path: blob/main/vendor/github.com/spf13/pflag/string.go
2875 views
package pflag12// -- string Value3type stringValue string45func newStringValue(val string, p *string) *stringValue {6*p = val7return (*stringValue)(p)8}910func (s *stringValue) Set(val string) error {11*s = stringValue(val)12return nil13}14func (s *stringValue) Type() string {15return "string"16}1718func (s *stringValue) String() string { return string(*s) }1920func stringConv(sval string) (interface{}, error) {21return sval, nil22}2324// GetString return the string value of a flag with the given name25func (f *FlagSet) GetString(name string) (string, error) {26val, err := f.getFlagType(name, "string", stringConv)27if err != nil {28return "", err29}30return val.(string), nil31}3233// StringVar defines a string flag with specified name, default value, and usage string.34// The argument p points to a string variable in which to store the value of the flag.35func (f *FlagSet) StringVar(p *string, name string, value string, usage string) {36f.VarP(newStringValue(value, p), name, "", usage)37}3839// StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.40func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) {41f.VarP(newStringValue(value, p), name, shorthand, usage)42}4344// StringVar defines a string flag with specified name, default value, and usage string.45// The argument p points to a string variable in which to store the value of the flag.46func StringVar(p *string, name string, value string, usage string) {47CommandLine.VarP(newStringValue(value, p), name, "", usage)48}4950// StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.51func StringVarP(p *string, name, shorthand string, value string, usage string) {52CommandLine.VarP(newStringValue(value, p), name, shorthand, usage)53}5455// String defines a string flag with specified name, default value, and usage string.56// The return value is the address of a string variable that stores the value of the flag.57func (f *FlagSet) String(name string, value string, usage string) *string {58p := new(string)59f.StringVarP(p, name, "", value, usage)60return p61}6263// StringP is like String, but accepts a shorthand letter that can be used after a single dash.64func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string {65p := new(string)66f.StringVarP(p, name, shorthand, value, usage)67return p68}6970// String defines a string flag with specified name, default value, and usage string.71// The return value is the address of a string variable that stores the value of the flag.72func String(name string, value string, usage string) *string {73return CommandLine.StringP(name, "", value, usage)74}7576// StringP is like String, but accepts a shorthand letter that can be used after a single dash.77func StringP(name, shorthand string, value string, usage string) *string {78return CommandLine.StringP(name, shorthand, value, usage)79}808182