diff --git a/src/help/command.ts b/src/help/command.ts index c047d2d39..199acffa0 100644 --- a/src/help/command.ts +++ b/src/help/command.ts @@ -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() diff --git a/test/help/format-command.test.ts b/test/help/format-command.test.ts index 5d0cb5568..500735056 100644 --- a/test/help/format-command.test.ts +++ b/test/help/format-command.test.ts @@ -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=