Skip to content

Commit

Permalink
fix: dont clobber description for multiple option calls (#2171)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Jul 18, 2022
1 parent b680ace commit f91d9b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/yargs-factory.ts
Expand Up @@ -1044,7 +1044,14 @@ export class YargsInstance {
}

const desc = opt.describe || opt.description || opt.desc;
this.describe(key, desc);
const descriptions = this.#usage.getDescriptions();
if (
!Object.prototype.hasOwnProperty.call(descriptions, key) ||
typeof desc === 'string'
) {
this.describe(key, desc);
}

if (opt.hidden) {
this.hide(key);
}
Expand Down
19 changes: 19 additions & 0 deletions test/usage.cjs
Expand Up @@ -4846,4 +4846,23 @@ describe('usage tests', () => {
' -v, --version Custom version description [boolean]',
]);
});

// https://github.com/yargs/yargs/issues/2169
it('allows multiple option calls to not clobber description', () => {
const r = checkUsage(() =>
yargs('--help')
.options({
arg: {desc: 'Old description', type: 'string', default: 'old'},
})
.options({arg: {default: 'new'}})
.wrap(null)
.parse()
);
r.logs[0]
.split('\n')
.slice(-1)[0]
.replace(/\s+/g, ' ')
.trim()
.should.equal('--arg Old description [string] [default: "new"]');
});
});

0 comments on commit f91d9b3

Please sign in to comment.