Add negatable output when using short flag names
Joe Schmitt authored 3 years ago
Alec Thomas committed 3 years ago
468 | 468 |
name := flag.Name
|
469 | 469 |
isBool := flag.IsBool()
|
470 | 470 |
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 |
}
|
472 | 476 |
} else {
|
473 | |
if haveShort {
|
474 | |
if isBool && flag.Tag.Negatable {
|
|
477 |
if isBool && flag.Tag.Negatable {
|
|
478 |
if haveShort {
|
475 | 479 |
flagString = fmt.Sprintf(" --[no-]%s", name)
|
476 | 480 |
} else {
|
|
481 |
flagString = fmt.Sprintf("--[no-]%s", name)
|
|
482 |
}
|
|
483 |
} else {
|
|
484 |
if haveShort {
|
477 | 485 |
flagString += fmt.Sprintf(" --%s", name)
|
478 | |
}
|
479 | |
} else {
|
480 | |
if isBool && flag.Tag.Negatable {
|
481 | |
flagString = fmt.Sprintf("--[no-]%s", name)
|
482 | 486 |
} else {
|
483 | 487 |
flagString += fmt.Sprintf("--%s", name)
|
484 | 488 |
}
|
28 | 28 |
Slice []string `help:"A slice of strings." placeholder:"STR"`
|
29 | 29 |
Map map[string]int `help:"A map of strings to ints."`
|
30 | 30 |
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."`
|
32 | 32 |
|
33 | 33 |
One struct {
|
34 | 34 |
Flag string `help:"Nested flag."`
|
|
75 | 75 |
--slice=STR,... A slice of strings.
|
76 | 76 |
--map=KEY=VALUE;... A map of strings to ints.
|
77 | 77 |
--required A required flag.
|
78 | |
--[no-]sort Is sortable or not.
|
|
78 |
-s, --[no-]sort Is sortable or not.
|
79 | 79 |
|
80 | 80 |
Commands:
|
81 | 81 |
one --required
|
|
116 | 116 |
--slice=STR,... A slice of strings.
|
117 | 117 |
--map=KEY=VALUE;... A map of strings to ints.
|
118 | 118 |
--required A required flag.
|
119 | |
--[no-]sort Is sortable or not.
|
|
119 |
-s, --[no-]sort Is sortable or not.
|
120 | 120 |
|
121 | 121 |
--flag=STRING Nested flag under two.
|
122 | 122 |
--required-two
|