Skip to content

Commit 9df796d

Browse files
committed
add pkg search
1 parent d335154 commit 9df796d

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

bin/pkg-search

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
d="$(cd "$(dirname "$0")/.." && pwd)"
4+
exec "$d"/libexec/search.ts "$@"

libexec/search.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env -S tea -E deno run --allow-env --allow-read --allow-net
2+
3+
import { parseFlags } from "cliffy/flags/mod.ts"
4+
import { usePantry, useInventory, useFlags } from "hooks"
5+
import * as semver from "semver"
6+
7+
useFlags()
8+
9+
const { unknown: [query] } = parseFlags(Deno.args)
10+
const pantry = usePantry()
11+
12+
const encoder = new TextEncoder()
13+
const print = (x: string) => Deno.stdout.write(encoder.encode(x))
14+
15+
for await (const pkg of pantry.ls()) {
16+
let output = false
17+
const bins: string[] = []
18+
for (const bin of await pantry.getProvides(pkg)) {
19+
if (bin.startsWith(query)) {
20+
output = true
21+
bins.push(bin)
22+
}
23+
}
24+
if (output) {
25+
print(`${pkg.project}: ${bins.join(', ')}`)
26+
} else if (pkg.project.startsWith(query)) {
27+
print(pkg.project.trim())
28+
output = true
29+
}
30+
if (output) {
31+
const rq = { project: pkg.project, constraint: new semver.Range('*') }
32+
const got = await useInventory().select(rq)
33+
print(`: ${got}\n`)
34+
}
35+
}

0 commit comments

Comments
 (0)