Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs]: Document and test boolean options consuming true/false strings #74

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ options can be:

* `opts.string` - a string or array of strings argument names to always treat as
strings
* `opts.boolean` - a boolean, string or array of strings to always treat as
booleans. if `true` will treat all double hyphenated arguments without equal signs
as boolean (e.g. affects `--foo`, not `-f` or `--foo=bar`)
* `opts.boolean` - A boolean, string, or array of strings to always treat as
booleans. If `true` will treat all double-hyphenated arguments without equal signs
as boolean (e.g. affects `--foo`, not `-f` or `--foo=bar`) A boolean option will
consume the following argument if it is the string `true` or `false`. (e.g. `--foo false`)
* `opts.alias` - an object mapping string names to strings or arrays of string
argument names to use as aliases
* `opts.default` - an object mapping string argument names to default values
Expand Down
16 changes: 16 additions & 0 deletions test/all_bool.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,19 @@ test('flag boolean true only affects double hyphen arguments without equals sign
t.deepEqual(typeof argv.honk, 'boolean');
t.end();
});

test('flag boolean true includes consuming true/false', function (t) {
var argv = parse(['--aaa', 'true', '--bbb', 'false', '--ccc=true', '--ddd=false'], {
boolean: true,
});

t.deepEqual(argv, {
aaa: true,
bbb: false,
ccc: 'true', // [sic] check legacy behaviour
ddd: 'false', // [sic] check legacy behaviour
_: [],
});

t.end();
});
Loading