Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.
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
6 changes: 5 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ export class Config implements IConfig {

async runCommand(id: string, argv: string[] = []) {
debug('runCommand %s %o', id, argv)
const c = this.findCommand(id)
let c = this.findCommand(id)
if (!c) {
c = this.findCommand('default')
argv.unshift(id)
}
if (!c) {
await this.runHook('command_not_found', {id})
throw new CLIError(`command ${id} not found`)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class Command {
static run() {
console.log('it works!')
}

static aliases = ['default']
}
2 changes: 2 additions & 0 deletions test/fixtures/typescript/src/hooks/postrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ export default function postrun(options: any) {
console.log('running ts postrun hook')
if (options.Command.id === 'foo:bar:test-result') {
console.log(options.result)
} else if (options.Command.id === 'foo:bar:default-result') {
console.log(options.argv)
}
}
7 changes: 7 additions & 0 deletions test/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ describe('typescript', () => {
await (ctx.config.runHook as any)('init', {id: 'myid', argv: ['foo']})
expect(ctx.stdout).to.equal('running ts init hook\n')
})

withConfig
.stdout()
.it('runs ts default command if command not found', async ctx => {
await ctx.config.runCommand('no-such-command')
expect(ctx.stdout).to.equal('running ts prerun hook\nit works!\nrunning ts postrun hook\n[ \'no-such-command\' ]\n')
})
})