yargs-parser 'strip-dashed' option is incompatible with yargs option names
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 519
- Forks
- 129
- Avg merge
- 1h 34m
- Merged PRs (30d)
- 1
Description
When specifying a command option (e.g. component-version), it is automatically converted to camel-case in the parsed object (i.e. componentVersion).
When using the strip-dashed option to remove the non camel-case version, yargs fails validation, because the non camel-case option is missing.
Related Code
yargs
.commandDir("./commands", {extensions: ["js", "ts"]})
.demandCommand()
.option("verbose", {description: "enable verbose logging for the command"})
.help()
.wrap(72)
.parserConfiguration(
{
"sort-commands": true,
"strip-dashed": false,
"strip-aliased": true
})
.argv;
import { Argv } from "yargs";
exports.command = "prerelease <component>";
exports.desc = "manage deployable artifacts";
exports.builder = (yargs: Argv) => {
yargs.positional("component", {
type: "string",
description: "The name of the component to deploy",
demandOption: true
});
yargs.option("component-version", {
type: "string",
description: "The version of the component to deploy",
demandOption: true,
})
};
exports.handler = (args: any): void => {
console.log(args) // expect {component: "name", componentVersion: "1.0.0" }
}
Instead I get
Missing required argument: component-version
My expectation would be that parsing succeeds, and yargs recognises the camel-case option.
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
Reproduce the issue with the shown command and command builder, focusing first on parserConfiguration({"strip-dashed": false}) and the demandOption validation for component-version. Check how the option is converted to componentVersion before validation. Done means parsing succeeds and produces the expected camel-case value without reporting the dashed option as missing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100