Support "yes", "1" and "true" for bool values.

This commit is contained in:
Alec Thomas
2019-11-13 08:16:32 +11:00
parent d15c8fca8d
commit cd3f64f045
4 changed files with 17 additions and 2 deletions
+11 -1
View File
@@ -217,7 +217,17 @@ func (boolMapper) Decode(ctx *DecodeContext, target reflect.Value) error {
token := ctx.Scan.Pop()
switch v := token.Value.(type) {
case string:
target.SetBool(strings.ToLower(v) == "true")
v = strings.ToLower(v)
switch v {
case "true", "1", "yes":
target.SetBool(true)
case "false", "0", "no":
target.SetBool(false)
default:
return errors.Errorf("bool value must be true, 1, yes, false, 0 or no but got %q", v)
}
case bool:
target.SetBool(v)