Merge pull request #166 from codegangsta/fix-generic-flag-help-text

Fix help text for generic flag to not insinuate that you can specify mul...
main
Dan Buch 10 years ago
commit 21d399c3fa

@ -69,10 +69,15 @@ type GenericFlag struct {
EnvVar string 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 { 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) { func (f GenericFlag) Apply(set *flag.FlagSet) {
val := f.Value val := f.Value
if f.EnvVar != "" { if f.EnvVar != "" {

@ -262,15 +262,14 @@ var genericFlagTests = []struct {
value cli.Generic value cli.Generic
expected string expected string
}{ }{
{"help", &Parser{}, "--help <nil>\t`-help option -help option` "}, {"test", &Parser{"abc", "def"}, "--test 'abc,def'\ttest flag"},
{"h", &Parser{}, "-h <nil>\t`-h option -h option` "}, {"t", &Parser{"abc", "def"}, "-t 'abc,def'\ttest flag"},
{"test", &Parser{}, "--test <nil>\t`-test option -test option` "},
} }
func TestGenericFlagHelpOutput(t *testing.T) { func TestGenericFlagHelpOutput(t *testing.T) {
for _, test := range genericFlagTests { 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() output := flag.String()
if output != test.expected { if output != test.expected {

Loading…
Cancel
Save