From 22dbe6ffdcc531d86c29c1be5b34880937284368 Mon Sep 17 00:00:00 2001 From: jszwedko Date: Thu, 8 Jan 2015 13:58:34 -0500 Subject: [PATCH] Fix help text for generic flag to not insinuate that you can specify multiple Feels like it may have been copied from StringSliceFlag or something, but update the output to be more consistent with other single value flags. Also added comments to the String and Apply functions. --- flag.go | 7 ++++++- flag_test.go | 7 +++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/flag.go b/flag.go index ddd6ef8..7426d37 100644 --- a/flag.go +++ b/flag.go @@ -67,10 +67,15 @@ type GenericFlag struct { EnvVar string } +// String returns the string representation of the generic flag to display the +// help text to the user (uses the String() method of the generic flag to show +// the value) func (f GenericFlag) String() string { - return withEnvHint(f.EnvVar, fmt.Sprintf("%s%s %v\t`%v` %s", prefixFor(f.Name), f.Name, f.Value, "-"+f.Name+" option -"+f.Name+" option", f.Usage)) + return withEnvHint(f.EnvVar, fmt.Sprintf("%s%s '%v'\t%v", prefixFor(f.Name), f.Name, f.Value, f.Usage)) } +// Apply takes the flagset and calls Set on the generic flag with the value +// provided by the user for parsing by the flag func (f GenericFlag) Apply(set *flag.FlagSet) { val := f.Value if f.EnvVar != "" { diff --git a/flag_test.go b/flag_test.go index 4f0ba55..3ed07cd 100644 --- a/flag_test.go +++ b/flag_test.go @@ -262,15 +262,14 @@ var genericFlagTests = []struct { value cli.Generic expected string }{ - {"help", &Parser{}, "--help \t`-help option -help option` "}, - {"h", &Parser{}, "-h \t`-h option -h option` "}, - {"test", &Parser{}, "--test \t`-test option -test option` "}, + {"test", &Parser{"abc", "def"}, "--test 'abc,def'\ttest flag"}, + {"t", &Parser{"abc", "def"}, "-t 'abc,def'\ttest flag"}, } func TestGenericFlagHelpOutput(t *testing.T) { for _, test := range genericFlagTests { - flag := cli.GenericFlag{Name: test.name} + flag := cli.GenericFlag{Name: test.name, Value: test.value, Usage: "test flag"} output := flag.String() if output != test.expected {