Skip to content

Commit

Permalink
fix: only replace command id in usage if it's at beginning of string (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley authored Jun 3, 2024
1 parent 85310aa commit 3916945
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/help/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ export class CommandHelp extends HelpFormatter {

const commandDescription = colorize(
this.config?.theme?.sectionDescription,
u.replace('<%= command.id %>', '').replace(standardId, '').replace(configuredId, '').trim(),
u
.replace('<%= command.id %>', '')
.replace(new RegExp(`^${standardId}`), '')
.replace(new RegExp(`^${configuredId}`), '')
.trim(),
)

const line = `${dollarSign} ${bin} ${command} ${commandDescription}`.trim()
Expand Down
47 changes: 47 additions & 0 deletions test/help/format-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,53 @@ ARGUMENTS
expect(output).to.equal(`USAGE
$ oclif apps:create`)
})

it('should output usage with hardcoded command', async () => {
const cmd = await makeLoadable(
makeCommandClass({
id: 'apps:create',
usage: ['apps:create'],
}),
)
const output = help.formatCommand(cmd)
expect(output).to.equal(`USAGE
$ oclif apps:create`)
})

it('should output default usage for single letter command', async () => {
const cmd = await makeLoadable(
makeCommandClass({
id: 'a',
flags: {
'a-flag': flags.string({char: 'a', options: ['a', 'aa', 'aaa']}),
},
}),
)
const output = help.formatCommand(cmd)
expect(output).to.equal(`USAGE
$ oclif a [-a a|aa|aaa]
FLAGS
-a, --a-flag=<option> <options: a|aa|aaa>`)
})

it('should output usage for single letter command', async () => {
const cmd = await makeLoadable(
makeCommandClass({
id: 'a',
flags: {
'a-flag': flags.string({char: 'a', options: ['a', 'aa', 'aaa']}),
},
usage: 'a [-a a|aa|aaa]',
}),
)
const output = help.formatCommand(cmd)
expect(output).to.equal(`USAGE
$ oclif a [-a a|aa|aaa]
FLAGS
-a, --a-flag=<option> <options: a|aa|aaa>`)
})
})

describe('examples', () => {
Expand Down

0 comments on commit 3916945

Please sign in to comment.