Support "yes", "1" and "true" for bool values.
This commit is contained in:
@@ -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:
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ linters:
|
|||||||
- maligned
|
- maligned
|
||||||
- lll
|
- lll
|
||||||
- gochecknoglobals
|
- gochecknoglobals
|
||||||
|
- wsl
|
||||||
|
- funlen
|
||||||
|
- gocognit
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
govet:
|
govet:
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user