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

Parsed Objects via dashed-options does not produce correct camel-case options #1620

Closed
libinvarghese opened this issue Apr 11, 2020 · 4 comments
Labels

Comments

@libinvarghese
Copy link

libinvarghese commented Apr 11, 2020

When providing an objects via object path options, to a dashed-option name, the generated camel-case option is not generated correctly.

const yargs = require('yargs');

yargs.option('filter-module', {
    alias: 'f'
  })
  .option('patternString', {
    alias: 'p'
  });

function parseCLI(cmd) {
  console.log(`Input to yargs.parse = ${cmd}`);
  yargs.parse(cmd, (error, argv, output) => {
    console.log(`Yargs.parse = ${JSON.stringify(argv)}`);
  });
}

// Bug
parseCLI('--filter-module.a 1 --filter-module.b 2');  // Incorrect camelCase
// Input to yargs.parse = --filter-module.a 1 --filter-module.b 2
// Yargs.parse = {"_":[],"filter-module":{"a":1,"b":2},"filterModule":{"a":[1,1],"b":[2,2]},"f":{"a":1,"b":2},"$0":"/run_dir/interp.js"}
parseCLI('--pattern-string.a 1 --pattern-string.b 2');   // Incorrect camelCase
// Input to yargs.parse = --pattern-string.a 1 --pattern-string.b 2
// Yargs.parse = {"_":[],"pattern-string":{"a":1,"b":2},"patternString":{"a":[1,1],"b":[2,2]},"p":{"a":1,"b":2},"$0":"/run_dir/interp.js"}

From the output you will notice that parse dashed options (filter-module and pattern-string) are valid, while the camel case options(filterModule & patternString) are incorrect.

Expected Behaviour

parseCLI('--filter-module.a 1 --filter-module.b 2');  // Incorrect camelCase
// Input to yargs.parse = --filter-module.a 1 --filter-module.b 2
// Yargs.parse = {"_":[],"filter-module":{"a":1,"b":2},"filterModule":{"a":1,"b":2},"f":{"a":1,"b":2},"$0":"/run_dir/interp.js"}

Actual Behaviour

parseCLI('--filter-module.a 1 --filter-module.b 2');  // Incorrect camelCase
// Input to yargs.parse = --filter-module.a 1 --filter-module.b 2
// Yargs.parse = {"_":[],"filter-module":{"a":1,"b":2},"filterModule":{"a":[1,1],"b":[2,2]},"f":{"a":1,"b":2},"$0":"/run_dir/interp.js"}

You can reproduce it via this repl.it

@mleguen
Copy link
Member

mleguen commented Apr 15, 2020

Reproduced on master branch.

@mleguen
Copy link
Member

mleguen commented Apr 15, 2020

I traced and fixed the bug upstream, see yargs/yargs-parser#267 and yargs/yargs-parser#268.

Waiting for the fix to be merged and released there.

@bcoe
Copy link
Member

bcoe commented Apr 16, 2020

@mleguen just released your patch to yargs-parser, a fresh install should fix this issue 👌

@bcoe bcoe closed this as completed Apr 16, 2020
@mleguen
Copy link
Member

mleguen commented Apr 17, 2020

OK for me, thanks @bcoe

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