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

Fix Boolean options with non boolean defaults #20

Merged
merged 1 commit into from
Apr 8, 2016

Conversation

elas7
Copy link
Member

@elas7 elas7 commented Apr 3, 2016

Inspired by this issue in minimist: https://github.com/substack/minimist/issues/44

It you have a boolean flag with a default to something that isn't a boolean. For example:

var parsed = yargs(process.argv.slice(2), {
  boolean: ['foo'],
  default: {foo: null}
})

Then calling with --foo will result in {"_": [], "foo": [null, true]}.

I updated setKey() to avoid creating an array if the key in argv is in flags.bools. Previously, it only checked if the current value for the key in argv was a Boolean, but that didn't consider the case when a non-Boolean is set by default.

Note that setting a non-Boolean default for a Boolean key can be useful, as in the referenced issue, to find out if a key was explicitly set by the user in the CLI.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 8c805bb on elas7:fix-boolean into 48b1e6a on yargs:master.

@bcoe bcoe merged commit 2dbe86b into yargs:master Apr 8, 2016
@elas7 elas7 deleted the fix-boolean branch April 9, 2016 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants