Skip to content

Commit

Permalink
feat: add error message for unsupported commands/package managers (#129)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <[email protected]>
  • Loading branch information
Zeko369 and antfu authored Feb 13, 2023
1 parent 5dd210b commit 1a7e9e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ dist
_storage.json

# System files
.DS_Store
.DS_Store
9 changes: 8 additions & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { AGENTS } from './agents'
import { exclude } from './utils'
import type { Runner } from './runner'

export class UnsupportedCommand extends Error {
constructor({ agent, command }: { agent: Agent; command: Command }) {
super(`Command "${command}" is not support by agent "${agent}"`)
}
}

export function getCommand(
agent: Agent,
command: Command,
Expand All @@ -17,7 +23,8 @@ export function getCommand(
return c(args)

if (!c)
throw new Error(`Command "${command}" is not support by agent "${agent}"`)
throw new UnsupportedCommand({ agent, command })

return c.replace('{0}', args.join(' ')).trim()
}

Expand Down
4 changes: 4 additions & 0 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getDefaultAgent, getGlobalAgent } from './config'
import type { DetectOptions } from './detect'
import { detect } from './detect'
import { getVoltaPrefix, remove } from './utils'
import { UnsupportedCommand } from './parse'

const DEBUG_SIGN = '?'

Expand All @@ -26,6 +27,9 @@ export async function runCli(fn: Runner, options: DetectOptions = {}) {
await run(fn, args, options)
}
catch (error) {
if (error instanceof UnsupportedCommand)
console.log(c.red(`\u2717 ${error.message}`))

process.exit(1)
}
}
Expand Down

0 comments on commit 1a7e9e4

Please sign in to comment.