Codebase list golang-github-alecthomas-kong / d48f4e5
Add negatable output when using short flag names Joe Schmitt authored 3 years ago Alec Thomas committed 3 years ago
2 changed file(s) with 14 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
468468 name := flag.Name
469469 isBool := flag.IsBool()
470470 if flag.Short != 0 {
471 flagString += fmt.Sprintf("-%c, --%s", flag.Short, name)
471 if isBool && flag.Tag.Negatable {
472 flagString += fmt.Sprintf("-%c, --[no-]%s", flag.Short, name)
473 } else {
474 flagString += fmt.Sprintf("-%c, --%s", flag.Short, name)
475 }
472476 } else {
473 if haveShort {
474 if isBool && flag.Tag.Negatable {
477 if isBool && flag.Tag.Negatable {
478 if haveShort {
475479 flagString = fmt.Sprintf(" --[no-]%s", name)
476480 } else {
481 flagString = fmt.Sprintf("--[no-]%s", name)
482 }
483 } else {
484 if haveShort {
477485 flagString += fmt.Sprintf(" --%s", name)
478 }
479 } else {
480 if isBool && flag.Tag.Negatable {
481 flagString = fmt.Sprintf("--[no-]%s", name)
482486 } else {
483487 flagString += fmt.Sprintf("--%s", name)
484488 }
2828 Slice []string `help:"A slice of strings." placeholder:"STR"`
2929 Map map[string]int `help:"A map of strings to ints."`
3030 Required bool `required help:"A required flag."`
31 Sort bool `negatable help:"Is sortable or not."`
31 Sort bool `negatable short:"s" help:"Is sortable or not."`
3232
3333 One struct {
3434 Flag string `help:"Nested flag."`
7575 --slice=STR,... A slice of strings.
7676 --map=KEY=VALUE;... A map of strings to ints.
7777 --required A required flag.
78 --[no-]sort Is sortable or not.
78 -s, --[no-]sort Is sortable or not.
7979
8080 Commands:
8181 one --required
116116 --slice=STR,... A slice of strings.
117117 --map=KEY=VALUE;... A map of strings to ints.
118118 --required A required flag.
119 --[no-]sort Is sortable or not.
119 -s, --[no-]sort Is sortable or not.
120120
121121 --flag=STRING Nested flag under two.
122122 --required-two