diff options
author | Eugene Otto <eotto@plaid.com> | 2022-09-30 02:24:13 -0700 |
---|---|---|
committer | Eugene Otto <eotto@plaid.com> | 2022-09-30 04:35:46 -0700 |
commit | 1bcf46b7907d4fc566a1382ad4eda4d0e9354e63 (patch) | |
tree | ee0f92886f2d46d1f4f6b0a63c93e068e8814dd2 /lib | |
parent | 41af0db78bba76cc7faccbf6adb400e65274f3a3 (diff) | |
download | slop-1bcf46b7907d4fc566a1382ad4eda4d0e9354e63.tar.gz |
Fix explicitly false booleans
When a boolean option is explicitly set to `false`, e.g.:
```bash
--option=false
```
it enters slop as the string value `'false'`. This commit updates the
`BoolOption` option handler to interpret `'false'` and various other falsey
values (`false`, `'false'`, `'no'`, `'off'`, `'0'`) as logically false.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/slop/types.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/slop/types.rb b/lib/slop/types.rb index 4ccd42e..83e4a0b 100644 --- a/lib/slop/types.rb +++ b/lib/slop/types.rb @@ -21,6 +21,8 @@ module Slop class BoolOption < Option attr_accessor :explicit_value + FALSE_VALUES = [false, 'false', 'no', 'off', '0'].freeze + def call(value) self.explicit_value = value !force_false? @@ -35,7 +37,7 @@ module Slop end def force_false? - explicit_value == false + FALSE_VALUES.include?(explicit_value) end def default_value |