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

yargs 17: option not listed in help output when coerced #1909

Closed
gr2m opened this issue Apr 8, 2021 · 1 comment · Fixed by #1911
Closed

yargs 17: option not listed in help output when coerced #1909

gr2m opened this issue Apr 8, 2021 · 1 comment · Fixed by #1911
Labels

Comments

@gr2m
Copy link

gr2m commented Apr 8, 2021

// 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 yargs@17.0.0-candidate.10

$ node index.js --help
Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
  --option1  option1 description                             [string] [required]

Result with yargs@16.2.0

$ 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

gr2m added a commit to octoherd/cli that referenced this issue Apr 8, 2021
@bcoe bcoe added the bug label Apr 11, 2021
bcoe added a commit that referenced this issue Apr 11, 2021
The trick we were using of .alias("foo", "foo") to "tell" yargs-parser about a key
using coerce has a bug such that help output is broken. We can instead use
.key (https://github.com/yargs/yargs-parser/blob/master/lib/yargs-parser.ts#L191) which
is designed for exactly our purposes (telling yargs-parser a key exists, without
setting attributes such as description).

Fixes #1909
bcoe added a commit that referenced this issue Apr 11, 2021
The trick we were using of .alias("foo", "foo") to "tell" yargs-parser about a key
using coerce has a bug such that help output is broken. We can instead use
.key (https://github.com/yargs/yargs-parser/blob/master/lib/yargs-parser.ts#L191) which
is designed for exactly our purposes (telling yargs-parser a key exists, without
setting attributes such as description).

Fixes #1909
bcoe added a commit that referenced this issue Apr 11, 2021
The trick we were using of .alias("foo", "foo") to "tell" yargs-parser about a key
using coerce has a bug such that help output is broken. We can instead use
.key (https://github.com/yargs/yargs-parser/blob/master/lib/yargs-parser.ts#L191) which
is designed for exactly our purposes (telling yargs-parser a key exists, without
setting attributes such as description).

Fixes #1909
bcoe added a commit that referenced this issue Apr 11, 2021
The trick we were using of .alias("foo", "foo") to "tell" yargs-parser about a key
using coerce has a bug such that help output is broken. We can instead use
.key (https://github.com/yargs/yargs-parser/blob/master/lib/yargs-parser.ts#L191) which
is designed for exactly our purposes (telling yargs-parser a key exists, without
setting attributes such as description).

Fixes #1909
@bcoe
Copy link
Member

bcoe commented Apr 11, 2021

@gr2m a fix is now published to + yargs@17.0.0-candidate.11, thank you for the feedback and solid bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants