Better help for maps.
This commit is contained in:
+15
-15
@@ -66,13 +66,13 @@ func TestHelp(t *testing.T) {
|
|||||||
A test app.
|
A test app.
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
--help Show context-sensitive help.
|
--help Show context-sensitive help.
|
||||||
--string=STRING A string flag.
|
--string=STRING A string flag.
|
||||||
--bool A bool flag with very long help that wraps a lot and is
|
--bool A bool flag with very long help that wraps a lot and is
|
||||||
verbose and is really verbose.
|
verbose and is really verbose.
|
||||||
--slice=STR,... A slice of strings.
|
--slice=STR,... A slice of strings.
|
||||||
--map=KEY=VALUE A map of strings to ints.
|
--map=KEY=VALUE;... A map of strings to ints.
|
||||||
--required A required flag.
|
--required A required flag.
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
one --required
|
one --required
|
||||||
@@ -106,15 +106,15 @@ Sub-sub-arg.
|
|||||||
Detailed help provided through the HelpProvider interface.
|
Detailed help provided through the HelpProvider interface.
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
--help Show context-sensitive help.
|
--help Show context-sensitive help.
|
||||||
--string=STRING A string flag.
|
--string=STRING A string flag.
|
||||||
--bool A bool flag with very long help that wraps a lot and is
|
--bool A bool flag with very long help that wraps a lot and is
|
||||||
verbose and is really verbose.
|
verbose and is really verbose.
|
||||||
--slice=STR,... A slice of strings.
|
--slice=STR,... A slice of strings.
|
||||||
--map=KEY=VALUE A map of strings to ints.
|
--map=KEY=VALUE;... A map of strings to ints.
|
||||||
--required A required flag.
|
--required A required flag.
|
||||||
|
|
||||||
--flag=STRING Nested flag under two.
|
--flag=STRING Nested flag under two.
|
||||||
--required-two
|
--required-two
|
||||||
|
|
||||||
--required-three
|
--required-three
|
||||||
|
|||||||
@@ -357,7 +357,7 @@ func (f *Flag) FormatPlaceHolder() string {
|
|||||||
return f.PlaceHolder + tail
|
return f.PlaceHolder + tail
|
||||||
}
|
}
|
||||||
if f.Value.IsMap() {
|
if f.Value.IsMap() {
|
||||||
return "KEY=VALUE" + tail
|
return "KEY=VALUE;..."
|
||||||
}
|
}
|
||||||
return strings.ToUpper(f.Name) + tail
|
return strings.ToUpper(f.Name) + tail
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -70,6 +70,16 @@ func jsonDecodeValue(sep rune, value interface{}) (string, error) {
|
|||||||
out = append(out, sel)
|
out = append(out, sel)
|
||||||
}
|
}
|
||||||
return JoinEscaped(out, sep), nil
|
return JoinEscaped(out, sep), nil
|
||||||
|
case map[string]interface{}:
|
||||||
|
out := []string{}
|
||||||
|
for key, el := range v {
|
||||||
|
sel, err := jsonDecodeValue(sep, el)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
out = append(out, fmt.Sprintf("%s=%s", key, sel))
|
||||||
|
}
|
||||||
|
return JoinEscaped(out, ';'), nil
|
||||||
case bool:
|
case bool:
|
||||||
if v {
|
if v {
|
||||||
return "true", nil
|
return "true", nil
|
||||||
|
|||||||
Reference in New Issue
Block a user