// index.js
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
const argv = yargs(hideBin(process.argv))
.option("option1", {
describe: "option1 description",
type: "string",
demandOption: true,
})
.option("option2", {
describe: "option2 description",
type: "string",
demandOption: true,
})
.coerce("option2", () => undefined).argv;
Result with [email protected]
$ node index.js --help
Options:
--help Show help [boolean]
--version Show version number [boolean]
--option1 option1 description [string] [required]
Result with [email protected]
$ node index.js --help
Options:
--help Show help [boolean]
--version Show version number [boolean]
--option1 option1 description [string] [required]
--option2 option2 description [string] [required]
Reproducible test case: https://runkit.com/gr2m/yargs-yargs-1909
Result with
[email protected]Result with
[email protected]Reproducible test case: https://runkit.com/gr2m/yargs-yargs-1909