Skip to content

Commit

Permalink
fix: stop inserting extra line breaks in description (#519)
Browse files Browse the repository at this point in the history
* fix: stop inserting extra line breaks in description

* chore: tests
  • Loading branch information
mdonnalley committed Oct 12, 2022
1 parent 59e6f51 commit 76aee62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
12 changes: 5 additions & 7 deletions src/help/command.ts
Expand Up @@ -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'))
}
}

Expand Down
7 changes: 4 additions & 3 deletions test/help/format-command.test.ts
Expand Up @@ -25,6 +25,7 @@ describe('formatCommand', () => {
static aliases = ['app:init', 'create']

static description = `first line
multiline help`

static enableJsonFlag = true
Expand Down Expand Up @@ -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']

Expand Down Expand Up @@ -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
})
Expand All @@ -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
})
Expand Down

0 comments on commit 76aee62

Please sign in to comment.