diff options
| author | spf13 <[email protected]> | 2014-06-27 09:29:20 -0400 |
|---|---|---|
| committer | spf13 <[email protected]> | 2014-06-27 09:29:20 -0400 |
| commit | b9035d0aef89271f98c3a2435e9cc614ffe5e81e (patch) | |
| tree | a47a1b482eced55d5af0d60065b87c590ff75868 /string.go | |
| parent | 94e98a55fb412fcbcfc302555cb990f5e1590627 (diff) | |
| parent | e4f7d00f344b0954fa3791a8527d10ba7334eceb (diff) | |
Merge branch 'master' of https://github.com/ogier/pflag
Conflicts:
flag.go
Diffstat (limited to 'string.go')
| -rw-r--r-- | string.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/string.go b/string.go new file mode 100644 index 0000000..65c0cb7 --- /dev/null +++ b/string.go @@ -0,0 +1,66 @@ +package pflag + +import "fmt" + +// -- string Value +type stringValue string + +func newStringValue(val string, p *string) *stringValue { + *p = val + return (*stringValue)(p) +} + +func (s *stringValue) Set(val string) error { + *s = stringValue(val) + return nil +} + +func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) } + +// StringVar defines a string flag with specified name, default value, and usage string. +// The argument p points to a string variable in which to store the value of the flag. +func (f *FlagSet) StringVar(p *string, name string, value string, usage string) { + f.VarP(newStringValue(value, p), name, "", usage) +} + +// Like StringVar, but accepts a shorthand letter that can be used after a single dash. +func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) { + f.VarP(newStringValue(value, p), name, shorthand, usage) +} + +// StringVar defines a string flag with specified name, default value, and usage string. +// The argument p points to a string variable in which to store the value of the flag. +func StringVar(p *string, name string, value string, usage string) { + CommandLine.VarP(newStringValue(value, p), name, "", usage) +} + +// Like StringVar, but accepts a shorthand letter that can be used after a single dash. +func StringVarP(p *string, name, shorthand string, value string, usage string) { + CommandLine.VarP(newStringValue(value, p), name, shorthand, usage) +} + +// String defines a string flag with specified name, default value, and usage string. +// The return value is the address of a string variable that stores the value of the flag. +func (f *FlagSet) String(name string, value string, usage string) *string { + p := new(string) + f.StringVarP(p, name, "", value, usage) + return p +} + +// Like String, but accepts a shorthand letter that can be used after a single dash. +func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string { + p := new(string) + f.StringVarP(p, name, shorthand, value, usage) + return p +} + +// String defines a string flag with specified name, default value, and usage string. +// The return value is the address of a string variable that stores the value of the flag. +func String(name string, value string, usage string) *string { + return CommandLine.StringP(name, "", value, usage) +} + +// Like String, but accepts a shorthand letter that can be used after a single dash. +func StringP(name, shorthand string, value string, usage string) *string { + return CommandLine.StringP(name, shorthand, value, usage) +} |
