From b2d6eca4520c4eb4ea2346777f611f014446d332 Mon Sep 17 00:00:00 2001 From: Cristian Dominguez Date: Mon, 30 Jan 2023 09:52:55 -0300 Subject: [PATCH 1/2] fix: allows space-separated commands as args --- src/commands/which.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/commands/which.ts b/src/commands/which.ts index 1b5296fb..015c40e5 100644 --- a/src/commands/which.ts +++ b/src/commands/which.ts @@ -12,14 +12,17 @@ export default class Which extends Command { async run(): Promise { const {argv} = await this.parse(Which) + + if (argv.length === 0) { + throw new Error('"which" expects a command name. Try something like "which your:command:here" ') + } + let command = argv if (argv.length === 1 && typeof argv[0] === 'string') { // If this if statement is true then the command to find was passed in as a single string, e.g. `mycli which "my command"` // So we must use the topicSeparator to split it into an array command = argv[0].split(this.config.topicSeparator) - } else { - throw new Error('"which" expects a command name. Try something like "which your:command:here" ') } const cmd = this.config.findCommand(command.join(':'), {must: true}) From 90c3db345db6ba9574745bec9a29f250eb24f943 Mon Sep 17 00:00:00 2001 From: Cristian Dominguez Date: Mon, 30 Jan 2023 18:00:28 -0300 Subject: [PATCH 2/2] test: add UT --- test/commands/which.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/commands/which.test.ts b/test/commands/which.test.ts index b13513b4..f2ea15e0 100644 --- a/test/commands/which.test.ts +++ b/test/commands/which.test.ts @@ -7,4 +7,12 @@ describe('which', () => { .it('which which', ctx => { expect(ctx.stdout).to.contain('@oclif/plugin-which') }) + + test + .stdout() + .command(['which']) + .catch(error => { + expect(error.message).to.contain('"which" expects a command name. Try something like "which your:command:here" ') + }) + .it('checks arg was provided') })