From cb2b3663accfea57535728ef304e8fe4b332655d Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Wed, 12 Oct 2022 09:00:16 -0600 Subject: [PATCH 1/2] fix: stop inserting extra line breaks in description --- src/help/command.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/help/command.ts b/src/help/command.ts index 81969ae4..787b49e9 100644 --- a/src/help/command.ts +++ b/src/help/command.ts @@ -156,20 +156,18 @@ export class CommandHelp extends HelpFormatter { const cmd = this.command let description: string[] | undefined - if (this.opts.hideCommandSummaryInDescription) { description = (cmd.description || '').split(POSSIBLE_LINE_FEED).slice(1) } else if (cmd.description) { - description = [ - ...(cmd.summary || '').split(POSSIBLE_LINE_FEED), + const summary = cmd.summary ? `${cmd.summary}\n` : null + description = summary ? [ + ...summary.split(POSSIBLE_LINE_FEED), ...(cmd.description || '').split(POSSIBLE_LINE_FEED), - ] + ] : (cmd.description || '').split(POSSIBLE_LINE_FEED) } if (description) { - // Lines separated with only one newline or more than 2 can be hard to read in the terminal. - // Always separate by two newlines. - return this.wrap(compact(description).join('\n\n')) + return this.wrap(description.join('\n')) } } From 4b098b961bce048ecd31b3744c51ce5f417621ba Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Wed, 12 Oct 2022 09:08:38 -0600 Subject: [PATCH 2/2] chore: tests --- test/help/format-command.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/help/format-command.test.ts b/test/help/format-command.test.ts index d208d87a..53ff6a57 100644 --- a/test/help/format-command.test.ts +++ b/test/help/format-command.test.ts @@ -25,6 +25,7 @@ describe('formatCommand', () => { static aliases = ['app:init', 'create'] static description = `first line + multiline help` static enableJsonFlag = true @@ -222,7 +223,7 @@ DESCRIPTION .commandHelp(class extends Command { static id = 'apps:create' - static description = 'description of apps:create\nthese values are after and will show up in the command description' + static description = 'description of apps:create\n\nthese values are after and will show up in the command description' static aliases = ['app:init', 'create'] @@ -259,7 +260,7 @@ ALIASES .commandHelp(class extends Command { static id = 'apps:create' - static description = 'root part of the description\nThe <%= config.bin %> CLI has <%= command.id %>' + static description = 'root part of the description\n\nThe <%= config.bin %> CLI has <%= command.id %>' static disableJsonFlag = true }) @@ -275,7 +276,7 @@ DESCRIPTION .commandHelp(class extends Command { static id = 'apps:create' - static description = 'root part of the description\r\nusing both carriage \nreturn and new line' + static description = 'root part of the description\r\n\nusing both carriage \n\nreturn and new line' static disableJsonFlag = true })