summaryrefslogtreecommitdiff
path: root/vendor/github.com/spf13/pflag/string.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vendor/github.com/spf13/pflag/string.go (renamed from vendor/github.com/victorhaggqvist/pflag/string.go)28
1 files changed, 21 insertions, 7 deletions
diff --git a/vendor/github.com/victorhaggqvist/pflag/string.go b/vendor/github.com/spf13/pflag/string.go
index 65c0cb7..04e0a26 100644
--- a/vendor/github.com/victorhaggqvist/pflag/string.go
+++ b/vendor/github.com/spf13/pflag/string.go
@@ -1,7 +1,5 @@
package pflag
-import "fmt"
-
// -- string Value
type stringValue string
@@ -14,8 +12,24 @@ func (s *stringValue) Set(val string) error {
*s = stringValue(val)
return nil
}
+func (s *stringValue) Type() string {
+ return "string"
+}
+
+func (s *stringValue) String() string { return string(*s) }
+
+func stringConv(sval string) (interface{}, error) {
+ return sval, nil
+}
-func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) }
+// GetString return the string value of a flag with the given name
+func (f *FlagSet) GetString(name string) (string, error) {
+ val, err := f.getFlagType(name, "string", stringConv)
+ if err != nil {
+ return "", err
+ }
+ return val.(string), nil
+}
// 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.
@@ -23,7 +37,7 @@ 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.
+// StringVarP is 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)
}
@@ -34,7 +48,7 @@ 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.
+// StringVarP is 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)
}
@@ -47,7 +61,7 @@ func (f *FlagSet) String(name string, value string, usage string) *string {
return p
}
-// Like String, but accepts a shorthand letter that can be used after a single dash.
+// StringP is 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)
@@ -60,7 +74,7 @@ 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.
+// StringP is 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)
}