Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allows space-separated commands as args #330

Merged
merged 2 commits into from
Jan 30, 2023
Merged
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
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')
})