Add support for negated boolean flags

Will automatically set a boolean Struct field to false if the flag starts with `--no-`, even when the default is `true`.

For example:
```
type Cmd struct {
  Output bool `default:"true"`
}
```

Calling
```
command
```
Will set `Output` to `true`, but
```
command --no-output
```
Will set `Output` to `false`.
This commit is contained in:
Joe Schmitt
2021-02-18 02:49:07 -05:00
committed by Alec Thomas
parent 541ee3302f
commit 2a0d7af9c5
3 changed files with 22 additions and 1 deletions
+1
View File
@@ -227,6 +227,7 @@ type Value struct {
Tag *Tag
Target reflect.Value
Required bool
Negated bool
Set bool // Set to true when this value is set through some mechanism.
Format string // Formatting directive, if applicable.
Position int // Position (for positional arguments).