Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/base-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
29 changes: 29 additions & 0 deletions test/lib/base-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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=<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'
Expand Down