Skip to content

Commit

Permalink
fix: allows space-separated commands as args (#330)
Browse files Browse the repository at this point in the history
* fix: allows space-separated commands as args

* test: add UT
  • Loading branch information
cristiand391 authored Jan 30, 2023
1 parent e89029b commit 819ed49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/commands/which.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ export default class Which extends Command {

async run(): Promise<void> {
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})
Expand Down
8 changes: 8 additions & 0 deletions test/commands/which.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

0 comments on commit 819ed49

Please sign in to comment.