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

duplicate-arguments-array: false breaks variadic positional arguments #2011

Open
markus456 opened this issue Aug 18, 2021 · 1 comment
Open
Labels

Comments

@markus456
Copy link

markus456 commented Aug 18, 2021

I decided to split off this from the problem originally mentioned in issue #1318 as it seems to have unintended side-effects. I've re-tested this with Yargs 17.0 and the problem remains. Unless I'm missing something obvious, this makes it impossible to use variadic positional arguments with "duplicate-arguments-array": false.


This seems to also affect variadic positional arguments:

var yargs = require("yargs")

yargs
    .parserConfiguration({
        "duplicate-arguments-array": false,
    })
    .command(
        "test <name> <key> <value> [extras...]",
        "Test positional arguments",
        function (yargs) {},
        function (argv) {
            console.log(argv.name, argv.key, argv.value, argv.extras)
        }
    )
    .parse()
$ node index.js test name key1 value1 key2 value2
name key1 value1 [ 'value2' ]

Removing "duplicate-arguments-array": false from the parser configuration results in expected output:

$ node index.js test name key1 value1 key2 value2
name key1 value1 [ 'key2', 'value2' ]

Explicitly specifying the type of the variadic argument as array with .positional doesn't seem to affect it. This was with yargs 16.2.0.

Originally posted by @markus456 in #1318 (comment)

@markus456
Copy link
Author

Here's an example with options included that shows the problem.

var yargs = require("yargs")

yargs
    .parserConfiguration({
        "duplicate-arguments-array": false,
    })
    .command(
        "test <name> <key> <value> [extras...]",
        "Test positional arguments",
        function (yargs) {},
        function (argv) {
            console.log(argv.name, argv.key, argv.value, argv.extras, argv["test-option"])
        }
    )
    .option("test-option",  {type: "string", describe: "a test option"})
    .parse()

Here's the output with "duplicate-arguments-array": false:

$ node index.js test name key1 value1 key2 value2 --test-option opt1 --test-option opt2
name key1 value1 [ 'value2' ] opt2

And here's without it:

$ node index.js test name key1 value1 key2 value2 --test-option opt1 --test-option opt2
name key1 value1 [ 'key2', 'value2' ] [ 'opt1', 'opt2' ]

@jly36963 jly36963 self-assigned this Jan 10, 2022
@jly36963 jly36963 removed their assignment Jan 29, 2023
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