From f534203873fe5d1847d1ec3298ea2646e690c7ef Mon Sep 17 00:00:00 2001 From: anasysuf Date: Fri, 21 Aug 2026 22:22:49 +0700 Subject: [PATCH] fix(help): join wrapped multi-line flag descriptions in getUsage --- lib/base-cmd.js | 7 ++++++- test/lib/base-cmd.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/base-cmd.js b/lib/base-cmd.js index d8500b5206a42..0f129f0c7b809 100644 --- a/lib/base-cmd.js +++ b/lib/base-cmd.js @@ -104,7 +104,12 @@ class BaseCommand { fullUsage.push('') for (const def of cmdDefs) { if (def.description) { - const desc = def.description.trim().split('\n')[0] + const desc = def.description + .trim() + .split('\n\n')[0] + .split('\n') + .map(l => l.trim()) + .join(' ') const shortcuts = def.short ? `-${def.short}` : '' const aliases = (def.alias || []).map(v => `--${v}`).join('|') const mainFlag = `--${def.key}` diff --git a/test/lib/base-cmd.js b/test/lib/base-cmd.js index ebe33b1b5aba4..f2bc20aa3e85f 100644 --- a/test/lib/base-cmd.js +++ b/test/lib/base-cmd.js @@ -263,6 +263,35 @@ t.test('getUsage() with both params and definitions', async t => { t.ok(usage.includes('--river'), 'includes river flag') }) +t.test('getUsage() with multi-line wrapped flag descriptions', async t => { + class TestCommand extends BaseCommand { + static name = 'test-command' + static description = 'Test command description' + static params = ['mountain'] + + static definitions = [ + new Definition('mountain', { + type: String, + default: 'everest', + description: ` + If you ask for a mountain and do not specify height, + then the default mountain will be returned. + + See mountain guide for more information. + `, + usage: '--mountain=', + }), + ] + } + + const usage = TestCommand.describeUsage + + t.ok( + usage.includes('If you ask for a mountain and do not specify height, then the default mountain will be returned.'), + 'includes full joined first paragraph of description without truncation' + ) +}) + t.test('getUsage() with subcommand without description', async t => { class SubCommandWithDesc extends BaseCommand { static name = 'with-desc'