Merge pull request #167 from codegangsta/use-double-quotes-in-defaults

Use double quotes in output for defaults
This commit is contained in:
Dan Buch 2015-01-08 16:28:32 -05:00
commit aee58516e6
2 changed files with 24 additions and 24 deletions

14
flag.go
View File

@ -73,7 +73,7 @@ type GenericFlag struct {
// help text to the user (uses the String() method of the generic flag to show // help text to the user (uses the String() method of the generic flag to show
// the value) // the value)
func (f GenericFlag) String() string { func (f GenericFlag) String() string {
return withEnvHint(f.EnvVar, fmt.Sprintf("%s%s '%v'\t%v", prefixFor(f.Name), f.Name, f.Value, 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 // Apply takes the flagset and calls Set on the generic flag with the value
@ -124,7 +124,7 @@ type StringSliceFlag struct {
func (f StringSliceFlag) String() string { func (f StringSliceFlag) String() string {
firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ") firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ")
pref := prefixFor(firstName) pref := prefixFor(firstName)
return withEnvHint(f.EnvVar, fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage)) return withEnvHint(f.EnvVar, fmt.Sprintf("%s [%v]\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage))
} }
func (f StringSliceFlag) Apply(set *flag.FlagSet) { func (f StringSliceFlag) Apply(set *flag.FlagSet) {
@ -183,7 +183,7 @@ type IntSliceFlag struct {
func (f IntSliceFlag) String() string { func (f IntSliceFlag) String() string {
firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ") firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ")
pref := prefixFor(firstName) pref := prefixFor(firstName)
return withEnvHint(f.EnvVar, fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage)) return withEnvHint(f.EnvVar, fmt.Sprintf("%s [%v]\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage))
} }
func (f IntSliceFlag) Apply(set *flag.FlagSet) { func (f IntSliceFlag) Apply(set *flag.FlagSet) {
@ -294,7 +294,7 @@ func (f StringFlag) String() string {
fmtString = "%s %v\t%v" fmtString = "%s %v\t%v"
if len(f.Value) > 0 { if len(f.Value) > 0 {
fmtString = "%s '%v'\t%v" fmtString = "%s \"%v\"\t%v"
} else { } else {
fmtString = "%s %v\t%v" fmtString = "%s %v\t%v"
} }
@ -330,7 +330,7 @@ type IntFlag struct {
} }
func (f IntFlag) String() string { func (f IntFlag) String() string {
return withEnvHint(f.EnvVar, fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), f.Value, f.Usage)) return withEnvHint(f.EnvVar, fmt.Sprintf("%s \"%v\"\t%v", prefixedNames(f.Name), f.Value, f.Usage))
} }
func (f IntFlag) Apply(set *flag.FlagSet) { func (f IntFlag) Apply(set *flag.FlagSet) {
@ -364,7 +364,7 @@ type DurationFlag struct {
} }
func (f DurationFlag) String() string { func (f DurationFlag) String() string {
return withEnvHint(f.EnvVar, fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), f.Value, f.Usage)) return withEnvHint(f.EnvVar, fmt.Sprintf("%s \"%v\"\t%v", prefixedNames(f.Name), f.Value, f.Usage))
} }
func (f DurationFlag) Apply(set *flag.FlagSet) { func (f DurationFlag) Apply(set *flag.FlagSet) {
@ -398,7 +398,7 @@ type Float64Flag struct {
} }
func (f Float64Flag) String() string { func (f Float64Flag) String() string {
return withEnvHint(f.EnvVar, fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), f.Value, f.Usage)) return withEnvHint(f.EnvVar, fmt.Sprintf("%s \"%v\"\t%v", prefixedNames(f.Name), f.Value, f.Usage))
} }
func (f Float64Flag) Apply(set *flag.FlagSet) { func (f Float64Flag) Apply(set *flag.FlagSet) {

View File

@ -38,7 +38,7 @@ var stringFlagTests = []struct {
{"help", "", "--help \t"}, {"help", "", "--help \t"},
{"h", "", "-h \t"}, {"h", "", "-h \t"},
{"h", "", "-h \t"}, {"h", "", "-h \t"},
{"test", "Something", "--test 'Something'\t"}, {"test", "Something", "--test \"Something\"\t"},
} }
func TestStringFlagHelpOutput(t *testing.T) { func TestStringFlagHelpOutput(t *testing.T) {
@ -75,22 +75,22 @@ var stringSliceFlagTests = []struct {
s := &cli.StringSlice{} s := &cli.StringSlice{}
s.Set("") s.Set("")
return s return s
}(), "--help '--help option --help option'\t"}, }(), "--help [--help option --help option]\t"},
{"h", func() *cli.StringSlice { {"h", func() *cli.StringSlice {
s := &cli.StringSlice{} s := &cli.StringSlice{}
s.Set("") s.Set("")
return s return s
}(), "-h '-h option -h option'\t"}, }(), "-h [-h option -h option]\t"},
{"h", func() *cli.StringSlice { {"h", func() *cli.StringSlice {
s := &cli.StringSlice{} s := &cli.StringSlice{}
s.Set("") s.Set("")
return s return s
}(), "-h '-h option -h option'\t"}, }(), "-h [-h option -h option]\t"},
{"test", func() *cli.StringSlice { {"test", func() *cli.StringSlice {
s := &cli.StringSlice{} s := &cli.StringSlice{}
s.Set("Something") s.Set("Something")
return s return s
}(), "--test '--test option --test option'\t"}, }(), "--test [--test option --test option]\t"},
} }
func TestStringSliceFlagHelpOutput(t *testing.T) { func TestStringSliceFlagHelpOutput(t *testing.T) {
@ -122,8 +122,8 @@ var intFlagTests = []struct {
name string name string
expected string expected string
}{ }{
{"help", "--help '0'\t"}, {"help", "--help \"0\"\t"},
{"h", "-h '0'\t"}, {"h", "-h \"0\"\t"},
} }
func TestIntFlagHelpOutput(t *testing.T) { func TestIntFlagHelpOutput(t *testing.T) {
@ -155,8 +155,8 @@ var durationFlagTests = []struct {
name string name string
expected string expected string
}{ }{
{"help", "--help '0'\t"}, {"help", "--help \"0\"\t"},
{"h", "-h '0'\t"}, {"h", "-h \"0\"\t"},
} }
func TestDurationFlagHelpOutput(t *testing.T) { func TestDurationFlagHelpOutput(t *testing.T) {
@ -189,14 +189,14 @@ var intSliceFlagTests = []struct {
value *cli.IntSlice value *cli.IntSlice
expected string expected string
}{ }{
{"help", &cli.IntSlice{}, "--help '--help option --help option'\t"}, {"help", &cli.IntSlice{}, "--help [--help option --help option]\t"},
{"h", &cli.IntSlice{}, "-h '-h option -h option'\t"}, {"h", &cli.IntSlice{}, "-h [-h option -h option]\t"},
{"h", &cli.IntSlice{}, "-h '-h option -h option'\t"}, {"h", &cli.IntSlice{}, "-h [-h option -h option]\t"},
{"test", func() *cli.IntSlice { {"test", func() *cli.IntSlice {
i := &cli.IntSlice{} i := &cli.IntSlice{}
i.Set("9") i.Set("9")
return i return i
}(), "--test '--test option --test option'\t"}, }(), "--test [--test option --test option]\t"},
} }
func TestIntSliceFlagHelpOutput(t *testing.T) { func TestIntSliceFlagHelpOutput(t *testing.T) {
@ -228,8 +228,8 @@ var float64FlagTests = []struct {
name string name string
expected string expected string
}{ }{
{"help", "--help '0'\t"}, {"help", "--help \"0\"\t"},
{"h", "-h '0'\t"}, {"h", "-h \"0\"\t"},
} }
func TestFloat64FlagHelpOutput(t *testing.T) { func TestFloat64FlagHelpOutput(t *testing.T) {
@ -262,8 +262,8 @@ var genericFlagTests = []struct {
value cli.Generic value cli.Generic
expected string expected string
}{ }{
{"test", &Parser{"abc", "def"}, "--test 'abc,def'\ttest flag"}, {"test", &Parser{"abc", "def"}, "--test \"abc,def\"\ttest flag"},
{"t", &Parser{"abc", "def"}, "-t 'abc,def'\ttest flag"}, {"t", &Parser{"abc", "def"}, "-t \"abc,def\"\ttest flag"},
} }
func TestGenericFlagHelpOutput(t *testing.T) { func TestGenericFlagHelpOutput(t *testing.T) {