Skip to content

Commit

Permalink
Merge 100f821 into d67464c
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Oct 17, 2023
2 parents d67464c + 100f821 commit f092dda
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import help from "./modes/help.ts"
import repl from "./modes/repl.ts"
import env from "./modes/env.ts"
import x from "./modes/x.ts"
import { AmbiguityError } from "./utils/error.ts"

const { usePantry, useSync } = hooks
const { flatmap } = utils
Expand Down Expand Up @@ -66,8 +67,15 @@ export default async function({ flags, ...opts }: Args, logger_prefix?: string)
}
} break
case 'install':
await ensure_pantry()
await install(await Promise.all(opts.args.map(x => parse_pkg_str(x, {latest: 'ok'}))))
try {
await ensure_pantry()
await install(await Promise.all(opts.args.map(x => parse_pkg_str(x, {latest: 'ok'}))))
} catch (err) {
if (err instanceof AmbiguityError) {
err.ctx = 'install'
}
throw err
}
break
case 'deintegrate':
await integrate('uninstall', opts)
Expand Down
10 changes: 9 additions & 1 deletion src/err-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@ export default function(err: Error) {
render('pantry error', err.message, [[JSON.stringify(err.ctx)]], 'pantry-error')
} else if (err instanceof AmbiguityError) {
const args = Deno.args.join(' ')
const projects = err.projects.map(p => [` %c pkgx +${p} ${args} %c`, 'background-color: black; color: white', 'color: initial'])
const projects = (() => {
if (err.ctx != 'install') {
return err.projects.map(p => [` %c pkgx +${p} ${args} %c`, 'background-color: black; color: white', 'color: initial'])
} else {
return err.projects.map(p => [` %c pkgx install ${p} %c`, 'background-color: black; color: white', 'color: initial'])
}
})()

render('multiple projects provide:', err.arg0, [
['pls be more specific:'],
[], ...projects, []
]
, 'ambiguous-pkgspec')

} else if (err instanceof ProvidesError) {
render('nothing provides:', err.arg0, [
['we haven’t pkgd this yet. %ccan you?', 'font-weight: bold']
Expand Down
1 change: 1 addition & 0 deletions src/modes/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default async function(pkgs: PackageRequirement[]) {
try {
await write(usrlocal, pkgs)
} catch (err) {
//FIXME we should check if /usr/local/bin is writable, but were having trouble with that
if (err instanceof Deno.errors.PermissionDenied) {
await write(Path.home().join(".local/bin"), pkgs)
} else {
Expand Down

0 comments on commit f092dda

Please sign in to comment.