Skip to content

Commit

Permalink
Support Yes/Y of true, No/N of false
Browse files Browse the repository at this point in the history
  • Loading branch information
shockerli committed Sep 21, 2024
1 parent a86d7d9 commit 9d653f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ func str2bool(str string) (bool, error) {
}

switch strings.ToLower(strings.TrimSpace(str)) {
case "on":
case "on", "yes", "y":
return true, nil
case "off":
case "off", "no", "n":
return false, nil
default:
return false, newErr(str, "bool")
Expand Down
8 changes: 8 additions & 0 deletions bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ func TestBoolE(t *testing.T) {
{uint8(0.00), false, false},
{nil, false, false},
{false, false, false},
{"NO", false, false},
{"no", false, false},
{"N", false, false},
{"n", false, false},
{"false", false, false},
{"FALSE", false, false},
{"False", false, false},
Expand Down Expand Up @@ -195,6 +199,10 @@ func TestBoolE(t *testing.T) {

// true/scale
{true, true, false},
{"YES", true, false},
{"yes", true, false},
{"Y", true, false},
{"y", true, false},
{"true", true, false},
{"TRUE", true, false},
{"True", true, false},
Expand Down

0 comments on commit 9d653f5

Please sign in to comment.