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

Cannot declare that boolean values do not accept an argument. #170

Closed
coreyfarrell opened this issue Apr 4, 2019 · 0 comments · Fixed by #171
Closed

Cannot declare that boolean values do not accept an argument. #170

coreyfarrell opened this issue Apr 4, 2019 · 0 comments · Fixed by #171

Comments

@coreyfarrell
Copy link
Contributor

coreyfarrell commented Apr 4, 2019

I'd like the ability to tell yargs-parser that boolean arguments do not accept values in the next argument. Lets say I have mytest.js:

#!/usr/bin/env node
'use strict';

const argv = require('yargs-parser')(process.argv.slice(2), {
	boolean: ['all'],
	narg: {
		all: 0
	},
	configuration: {
		'halt-at-non-option': true
	}
});
console.log(argv);

Currently:

$ ./mytest.js --all echo hi
{ _: [ 'echo', 'hi' ], all: true }
$ ./mytest.js --all true
{ _: [], all: true }
$ ./mytest.js --all false
{ _: [], all: false }
$ ./mytest.js --no-all true
{ _: [ 'true' ], all: false }
$ ./mytest.js --no-all false
{ _: [ 'false' ], all: false }

I feel that narg: {all: 0} should tell yargs-parser that --all should be processed without looking at the next argument. I think it's only valid to set narg of a boolean to 0 or 1. The following shows the desired output for the currently failing test cases:

$ ./mytest.js --all true
{ _: [ 'true' ], all: true }
$ ./mytest.js --all false
{ _: [ 'false' ], all: true }
coreyfarrell added a commit to coreyfarrell/yargs-parser that referenced this issue Apr 4, 2019
This causes boolean arguments to honor an narg setting of zero.

Fixes yargs#170
coreyfarrell added a commit to coreyfarrell/yargs-parser that referenced this issue Apr 4, 2019
This causes boolean arguments to honor an narg setting of zero.

Fixes yargs#170
@bcoe bcoe closed this as completed in #171 May 5, 2019
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 a pull request may close this issue.

1 participant