diff --git a/lib/yargs-factory.ts b/lib/yargs-factory.ts index 60c61266e..c093dbc36 100644 --- a/lib/yargs-factory.ts +++ b/lib/yargs-factory.ts @@ -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); } diff --git a/test/usage.cjs b/test/usage.cjs index 31138889d..d80770879 100644 --- a/test/usage.cjs +++ b/test/usage.cjs @@ -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"]'); + }); });