Merge pull request #79 from rschmukler/master

remove quotes for empty StringFlags
This commit is contained in:
Jeremy Saenz 2014-04-14 09:59:48 -07:00
commit 07c53fda7a
2 changed files with 16 additions and 4 deletions

11
flag.go
View File

@ -157,7 +157,16 @@ type StringFlag struct {
} }
func (f StringFlag) String() string { 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) { func (f StringFlag) Apply(set *flag.FlagSet) {

View File

@ -28,16 +28,19 @@ func TestBoolFlagHelpOutput(t *testing.T) {
var stringFlagTests = []struct { var stringFlagTests = []struct {
name string name string
value string
expected string expected string
}{ }{
{"help", "--help ''\t"}, {"help", "", "--help \t"},
{"h", "-h ''\t"}, {"h", "", "-h \t"},
{"h", "", "-h \t"},
{"test", "Something", "--test 'Something'\t"},
} }
func TestStringFlagHelpOutput(t *testing.T) { func TestStringFlagHelpOutput(t *testing.T) {
for _, test := range stringFlagTests { for _, test := range stringFlagTests {
flag := cli.StringFlag{Name: test.name} flag := cli.StringFlag{Name: test.name, Value: test.value}
output := flag.String() output := flag.String()
if output != test.expected { if output != test.expected {