Add negatable output when using short flag names
This commit is contained in:
@@ -469,17 +469,21 @@ func formatFlag(haveShort bool, flag *Flag) string {
|
|||||||
name := flag.Name
|
name := flag.Name
|
||||||
isBool := flag.IsBool()
|
isBool := flag.IsBool()
|
||||||
if flag.Short != 0 {
|
if flag.Short != 0 {
|
||||||
flagString += fmt.Sprintf("-%c, --%s", flag.Short, name)
|
if isBool && flag.Tag.Negatable {
|
||||||
|
flagString += fmt.Sprintf("-%c, --[no-]%s", flag.Short, name)
|
||||||
|
} else {
|
||||||
|
flagString += fmt.Sprintf("-%c, --%s", flag.Short, name)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if haveShort {
|
if isBool && flag.Tag.Negatable {
|
||||||
if isBool && flag.Tag.Negatable {
|
if haveShort {
|
||||||
flagString = fmt.Sprintf(" --[no-]%s", name)
|
flagString = fmt.Sprintf(" --[no-]%s", name)
|
||||||
} else {
|
} else {
|
||||||
flagString += fmt.Sprintf(" --%s", name)
|
flagString = fmt.Sprintf("--[no-]%s", name)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if isBool && flag.Tag.Negatable {
|
if haveShort {
|
||||||
flagString = fmt.Sprintf("--[no-]%s", name)
|
flagString += fmt.Sprintf(" --%s", name)
|
||||||
} else {
|
} else {
|
||||||
flagString += fmt.Sprintf("--%s", name)
|
flagString += fmt.Sprintf("--%s", name)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -29,7 +29,7 @@ func TestHelp(t *testing.T) {
|
|||||||
Slice []string `help:"A slice of strings." placeholder:"STR"`
|
Slice []string `help:"A slice of strings." placeholder:"STR"`
|
||||||
Map map[string]int `help:"A map of strings to ints."`
|
Map map[string]int `help:"A map of strings to ints."`
|
||||||
Required bool `required help:"A required flag."`
|
Required bool `required help:"A required flag."`
|
||||||
Sort bool `negatable help:"Is sortable or not."`
|
Sort bool `negatable short:"s" help:"Is sortable or not."`
|
||||||
|
|
||||||
One struct {
|
One struct {
|
||||||
Flag string `help:"Nested flag."`
|
Flag string `help:"Nested flag."`
|
||||||
@@ -76,7 +76,7 @@ Flags:
|
|||||||
--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.
|
||||||
--[no-]sort Is sortable or not.
|
-s, --[no-]sort Is sortable or not.
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
one --required
|
one --required
|
||||||
@@ -117,7 +117,7 @@ Flags:
|
|||||||
--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.
|
||||||
--[no-]sort Is sortable or not.
|
-s, --[no-]sort Is sortable or not.
|
||||||
|
|
||||||
--flag=STRING Nested flag under two.
|
--flag=STRING Nested flag under two.
|
||||||
--required-two
|
--required-two
|
||||||
|
|||||||
Reference in New Issue
Block a user