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
+1 -1
View File
@@ -12,7 +12,7 @@ jobs:
command: | command: |
go get -v github.com/jstemmer/go-junit-report go get -v github.com/jstemmer/go-junit-report
go get -v -t -d ./... go get -v -t -d ./...
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s v1.15.0 curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s v1.21.0
mkdir ~/report mkdir ~/report
when: always when: always
- run: - run:
+3
View File
@@ -10,6 +10,9 @@ linters:
- maligned - maligned
- lll - lll
- gochecknoglobals - gochecknoglobals
- wsl
- funlen
- gocognit
linters-settings: linters-settings:
govet: govet:
+2
View File
@@ -7,3 +7,5 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.2.2 github.com/stretchr/testify v1.2.2
) )
go 1.13
+11 -1
View File
@@ -217,7 +217,17 @@ func (boolMapper) Decode(ctx *DecodeContext, target reflect.Value) error {
token := ctx.Scan.Pop() token := ctx.Scan.Pop()
switch v := token.Value.(type) { switch v := token.Value.(type) {
case string: 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: case bool:
target.SetBool(v) target.SetBool(v)