Allow bool flags to be set to true or false explicitly.

This commit is contained in:
Alec Thomas
2018-09-11 23:57:18 +10:00
parent 862837e6fa
commit 844494faff
2 changed files with 17 additions and 1 deletions
+6 -1
View File
@@ -211,7 +211,12 @@ func (r *Registry) RegisterDefaults() *Registry {
type boolMapper struct{}
func (boolMapper) Decode(ctx *DecodeContext, target reflect.Value) error {
target.SetBool(true)
if ctx.Scan.Peek().Type == FlagValueToken {
token := ctx.Scan.Pop()
target.SetBool(token.Value == "true")
} else {
target.SetBool(true)
}
return nil
}
func (boolMapper) IsBool() bool { return true }