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

Commands are not parsed if preceded by -- #1527

Open
l1bbcsg opened this issue Jan 21, 2020 · 4 comments
Open

Commands are not parsed if preceded by -- #1527

l1bbcsg opened this issue Jan 21, 2020 · 4 comments
Labels

Comments

@l1bbcsg
Copy link

l1bbcsg commented Jan 21, 2020

Yargs version: 15.0.0 and above, version 14.2.0 is not affected.
#1459 looks like it could have introduced this.

Setup:

require('yargs')
	.array('array')
	.string('string')
	.command(
		'command',
		'does nothing',
		() => {},
		() => console.log('command executed')
	)
	.demandCommand()
	.argv;
node index.js --array foo bar -- command

Causes Not enough non-option arguments: got 0, need at least 1.

-- here is used to break populating array argument, otherwise command would be parsed as one of its values along with foo and bar and not as a command.

As a result it's not possible to put commands after array arguments at all, while other argument types can precede commands, this works fine for example:

node index.js --string foo command
@mleguen
Copy link
Member

mleguen commented Jan 22, 2020

-- is no longer used in yargs to stop populating arrays, but to stop parsing arguments, as does npm run for example:

npm run script -- scriptarg1 scriptarg2 ... scriptargn

scriptarg1 scriptarg2 ... scriptargn will be passed to script without being parsed by npm.

However, we should fix the documentation, which still indicate -- as a way to stop populating arrays.

@mxl
Copy link

mxl commented Feb 4, 2020

So how should we put command after array argument?

@mleguen
Copy link
Member

mleguen commented Feb 4, 2020

@mxl AFAIK, yargs does not support commands after positionals (array or not), nor commands after array options.

@mxl
Copy link

mxl commented Feb 4, 2020

@l1bbcsg @mleguen I found the way to specify command with array argument. Array argument should be specified after command:

node index.js command --array one two

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants