Strange implicit camel-case conversion when use both unknown-options-as-args and alias
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 519
- Forks
- 129
- Avg merge
- 1h 34m
- Merged PRs (30d)
- 1
Description
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the two yargs-parser@20.2.6 examples from the issue and compare handling of unknown-options-as-args with the alias for out-dir. Trace the parser's alias and camel-case conversion paths to determine why --outDir changes classification. Done means the behavior is documented by a regression test and matches the intended handling of the camel-case option.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100