Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop inserting extra line breaks in description #519

Merged
merged 2 commits into from Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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