aboutsummaryrefslogtreecommitdiff
path: root/string.go
diff options
context:
space:
mode:
authorEric Paris <[email protected]>2015-06-22 14:19:06 -0500
committerEric Paris <[email protected]>2015-06-22 14:19:06 -0500
commit0367f40254871b491ab74dbe3cc237f06fb34f27 (patch)
tree540c2f9b6983fcc366426429ff977a5a46c3fd45 /string.go
parent381cb823881391d5673cf2fc41e38feba8a8e49a (diff)
parent1e0a23de9163cb0706137856f1d060f88e3f277c (diff)
Merge pull request #25 from eparis/GetFlagType
Add new FlagSet.Get{Int,String,...} accessor functions
Diffstat (limited to 'string.go')
-rw-r--r--string.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/string.go b/string.go
index 362fbf8..f89ea8b 100644
--- a/string.go
+++ b/string.go
@@ -20,6 +20,19 @@ func (s *stringValue) Type() string {
func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) }
+func stringConv(sval string) (interface{}, error) {
+ return sval, nil
+}
+
+// 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.
func (f *FlagSet) StringVar(p *string, name string, value string, usage string) {