From cd3f64f045bb42ea6aa96ae60231e3817380a543 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Wed, 13 Nov 2019 08:16:32 +1100 Subject: [PATCH] Support "yes", "1" and "true" for bool values. --- .circleci/config.yml | 2 +- .golangci.yml | 3 +++ go.mod | 2 ++ mapper.go | 12 +++++++++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 035a373..eb50adf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,7 +12,7 @@ jobs: command: | go get -v github.com/jstemmer/go-junit-report 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 when: always - run: diff --git a/.golangci.yml b/.golangci.yml index 0b9ebc2..48925a8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,6 +10,9 @@ linters: - maligned - lll - gochecknoglobals + - wsl + - funlen + - gocognit linters-settings: govet: diff --git a/go.mod b/go.mod index 757bb09..c6f418f 100644 --- a/go.mod +++ b/go.mod @@ -7,3 +7,5 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stretchr/testify v1.2.2 ) + +go 1.13 diff --git a/mapper.go b/mapper.go index 58e45bb..a2a60e4 100644 --- a/mapper.go +++ b/mapper.go @@ -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)