From 312151dca45195f2d66f9f4e57299839cd449df8 Mon Sep 17 00:00:00 2001 From: Ryan Schmukler Date: Fri, 11 Apr 2014 15:09:59 -0400 Subject: [PATCH] remove quotes for empty StringFlags --- flag.go | 11 ++++++++++- flag_test.go | 9 ++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/flag.go b/flag.go index d0af858..59dbdf7 100644 --- a/flag.go +++ b/flag.go @@ -157,7 +157,16 @@ type StringFlag struct { } func (f StringFlag) String() string { - return fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), f.Value, f.Usage) + var fmtString string + fmtString = "%s %v\t%v" + + if len(f.Value) > 0 { + fmtString = "%s '%v'\t%v" + } else { + fmtString = "%s %v\t%v" + } + + return fmt.Sprintf(fmtString, prefixedNames(f.Name), f.Value, f.Usage) } func (f StringFlag) Apply(set *flag.FlagSet) { diff --git a/flag_test.go b/flag_test.go index db8892f..45cfae3 100644 --- a/flag_test.go +++ b/flag_test.go @@ -28,16 +28,19 @@ func TestBoolFlagHelpOutput(t *testing.T) { var stringFlagTests = []struct { name string + value string expected string }{ - {"help", "--help ''\t"}, - {"h", "-h ''\t"}, + {"help", "", "--help \t"}, + {"h", "", "-h \t"}, + {"h", "", "-h \t"}, + {"test", "Something", "--test 'Something'\t"}, } func TestStringFlagHelpOutput(t *testing.T) { for _, test := range stringFlagTests { - flag := cli.StringFlag{Name: test.name} + flag := cli.StringFlag{Name: test.name, Value: test.value} output := flag.String() if output != test.expected {