diff --git a/src/registerCommands.ts b/src/registerCommands.ts index 93f86edd..a24f5146 100644 --- a/src/registerCommands.ts +++ b/src/registerCommands.ts @@ -217,6 +217,13 @@ export default function(yargs: Argv, groupMap: GroupMap): void { return dojoYargs; }, (argv: any) => { + const isGroupCommand = Boolean(argv._.length); + if (isGroupCommand) { + const groupCommand = groupMap.get(argv._[0]); + if (!groupCommand || !groupCommand.get(argv._[1])) { + throw `Unable to find given command`; + } + } console.log(formatHelp(argv, groupMap)); } ) diff --git a/tests/unit/registerCommands.ts b/tests/unit/registerCommands.ts index 95c51c06..02e2eb7d 100644 --- a/tests/unit/registerCommands.ts +++ b/tests/unit/registerCommands.ts @@ -93,18 +93,43 @@ registerSuite('registerCommands', { help.reset(); yargsStub.command.lastCall.args[3]({ _: [], h: true }); assert.isTrue(help.calledOnce); + assert.isTrue(consoleLogStub.calledOnce); }, 'group help called'() { const help = mockModule.getMock('./help').formatHelp; help.reset(); yargsStub.command.firstCall.args[3]({ _: ['group'], h: true }); assert.isTrue(help.calledOnce); + assert.isTrue(consoleLogStub.calledOnce); }, 'command help called'() { const help = mockModule.getMock('./help').formatHelp; help.reset(); yargsStub.command.secondCall.args[3]({ _: ['group', 'command'], h: true }); assert.isTrue(help.calledOnce); + assert.isTrue(consoleLogStub.calledOnce); + }, + 'error if help called on non existant group'() { + const help = mockModule.getMock('./help').formatHelp; + help.reset(); + try { + yargsStub.command.lastCall.args[3]({ _: ['nonexistant'], h: true }); + assert.fail(null, null, 'getting unknown group should throw an error'); + } catch { + assert.isTrue(help.notCalled); + assert.isTrue(consoleLogStub.notCalled); + } + }, + 'error if help called on non existant command'() { + const help = mockModule.getMock('./help').formatHelp; + help.reset(); + try { + yargsStub.command.lastCall.args[3]({ _: ['group', 'nonexistant'], h: true }); + assert.fail(null, null, 'getting unknown command should throw an error'); + } catch { + assert.isTrue(help.notCalled); + assert.isTrue(consoleLogStub.notCalled); + } } } },