diff --git a/help.go b/help.go index fd2f758..d9f65bf 100644 --- a/help.go +++ b/help.go @@ -469,17 +469,21 @@ func formatFlag(haveShort bool, flag *Flag) string { name := flag.Name isBool := flag.IsBool() 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 { - if haveShort { - if isBool && flag.Tag.Negatable { + if isBool && flag.Tag.Negatable { + if haveShort { flagString = fmt.Sprintf(" --[no-]%s", name) } else { - flagString += fmt.Sprintf(" --%s", name) + flagString = fmt.Sprintf("--[no-]%s", name) } } else { - if isBool && flag.Tag.Negatable { - flagString = fmt.Sprintf("--[no-]%s", name) + if haveShort { + flagString += fmt.Sprintf(" --%s", name) } else { flagString += fmt.Sprintf("--%s", name) } diff --git a/help_test.go b/help_test.go index 71266b4..aa1a984 100644 --- a/help_test.go +++ b/help_test.go @@ -29,7 +29,7 @@ func TestHelp(t *testing.T) { Slice []string `help:"A slice of strings." placeholder:"STR"` Map map[string]int `help:"A map of strings to ints."` 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 { Flag string `help:"Nested flag."` @@ -76,7 +76,7 @@ Flags: --slice=STR,... A slice of strings. --map=KEY=VALUE;... A map of strings to ints. --required A required flag. - --[no-]sort Is sortable or not. + -s, --[no-]sort Is sortable or not. Commands: one --required @@ -117,7 +117,7 @@ Flags: --slice=STR,... A slice of strings. --map=KEY=VALUE;... A map of strings to ints. --required A required flag. - --[no-]sort Is sortable or not. + -s, --[no-]sort Is sortable or not. --flag=STRING Nested flag under two. --required-two