Skip to content

Commit 11303eb

Browse files
shadowspawnljharb
andcommitted
[Docs]: Document and test boolean options consuming true/false strings
Fixes #64 Co-authored-by: Jordan Harband <[email protected]>
1 parent bedaa8b commit 11303eb

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ options can be:
7272

7373
* `opts.string` - a string or array of strings argument names to always treat as
7474
strings
75-
* `opts.boolean` - a boolean, string or array of strings to always treat as
76-
booleans. if `true` will treat all double hyphenated arguments without equal signs
77-
as boolean (e.g. affects `--foo`, not `-f` or `--foo=bar`)
75+
* `opts.boolean` - A boolean, string, or array of strings to always treat as
76+
booleans. If `true` will treat all double-hyphenated arguments without equal signs
77+
as boolean (e.g. affects `--foo`, not `-f` or `--foo=bar`) A boolean option will
78+
consume the following argument if it is the string `true` or `false`. (e.g. `--foo false`)
7879
* `opts.alias` - an object mapping string names to strings or arrays of string
7980
argument names to use as aliases
8081
* `opts.default` - an object mapping string argument names to default values

test/all_bool.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,19 @@ test('flag boolean true only affects double hyphen arguments without equals sign
3232
t.deepEqual(typeof argv.honk, 'boolean');
3333
t.end();
3434
});
35+
36+
test('flag boolean true includes consuming true/false', function (t) {
37+
var argv = parse(['--aaa', 'true', '--bbb', 'false', '--ccc=true', '--ddd=false'], {
38+
boolean: true,
39+
});
40+
41+
t.deepEqual(argv, {
42+
aaa: true,
43+
bbb: false,
44+
ccc: 'true', // [sic] check legacy behaviour
45+
ddd: 'false', // [sic] check legacy behaviour
46+
_: [],
47+
});
48+
49+
t.end();
50+
});

0 commit comments

Comments
 (0)