Add negatable tag to set a bool to be negatable.

If negatable, add `--[no-]` prefix to help.
This commit is contained in:
Joe Schmitt
2021-02-18 10:55:55 -05:00
committed by Alec Thomas
parent 2a0d7af9c5
commit 2fdddc4f51
7 changed files with 34 additions and 5 deletions
+10 -2
View File
@@ -472,9 +472,17 @@ func formatFlag(haveShort bool, flag *Flag) string {
flagString += fmt.Sprintf("-%c, --%s", flag.Short, name)
} else {
if haveShort {
flagString += fmt.Sprintf(" --%s", name)
if isBool && flag.Tag.Negatable {
flagString = fmt.Sprintf(" --[no-]%s", name)
} else {
flagString += fmt.Sprintf(" --%s", name)
}
} else {
flagString += fmt.Sprintf("--%s", name)
if isBool && flag.Tag.Negatable {
flagString = fmt.Sprintf("--[no-]%s", name)
} else {
flagString += fmt.Sprintf("--%s", name)
}
}
}
if !isBool {