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

fix(coerce): options using coerce now displayed in help #1911

Merged
merged 2 commits into from Apr 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/yargs-factory.ts
Expand Up @@ -368,7 +368,7 @@ export class YargsInstance {
// This noop tells yargs-parser about the existence of the option
// represented by "keys", so that it can apply camel case expansion
// if needed:
this.alias(keys, keys);
this.#options.key[keys] = true;
this.#globalMiddleware.addCoerceMiddleware(
(
argv: Arguments,
Expand Down
19 changes: 19 additions & 0 deletions test/yargs.cjs
Expand Up @@ -2176,6 +2176,25 @@ describe('yargs dsl tests', () => {
yargs().coerce('c');
}, /coerce callback must be provided/);
});

// Refs: https://github.com/yargs/yargs/issues/1909
it('shows coerced option in help', async () => {
const help = await yargs()
.option('option1', {
describe: 'option1 description',
type: 'string',
demandOption: true,
})
.option('option2', {
describe: 'option2 description',
type: 'string',
demandOption: true,
})
.coerce('option2', () => undefined)
.getHelp();
console.info(help);
help.should.match(/option2 description/);
});
});

describe('stop parsing', () => {
Expand Down