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

Strange implicit camel-case conversion when use both unknown-options-as-args and alias #359

Open
weareoutman opened this issue Mar 6, 2021 · 0 comments
Labels

Comments

@weareoutman
Copy link

weareoutman commented Mar 6, 2021

Given code below:

const result = require("yargs-parser")(
  ["--foo", "bar", "--outDir", "dist"],
  {
    string: ["_", "foo", "out-dir"],
    configuration: {
      "unknown-options-as-args": true 
    }
  }
);

console.log(result);

This will print:

{ _: [ '--outDir', 'dist' ], foo: 'bar' }

In which outDir is parsed as a positional argument. This makes sense because outDir is not presented in string, even though its kebab-case variation presented.

However, when I set an alias for out-dir, It behaves in another way:

const result = require("yargs-parser")(
  ["--foo", "bar", "--outDir", "dist"],
  {
    string: ["_", "foo", "out-dir"],
    configuration: {
      "unknown-options-as-args": true 
    },
    alias: {
      "o": "out-dir"
    }
  }
);

console.log(result);

This will print:

{ _: [], foo: 'bar', outDir: 'dist', o: 'dist', 'out-dir': 'dist' }

In which the former unknown option outDir is parsed as a named argument now. I don't know if there are some implicit conversions under the hood?

If the camel-case conversion is intended, I hope the first example will treat outDir as a known named argument too.

Tested in the current version of yargs-parser@20.2.6

@weareoutman weareoutman changed the title Strange implicitly camel-case conversion when use both unknown-options-as-args and alias Strange implicit camel-case conversion when use both unknown-options-as-args and alias Mar 6, 2021
@bcoe bcoe added the bug label Mar 8, 2021
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

2 participants