Give each channel a package index
orbit-index:latest in a channel lists its packages. Search reads it and falls back to the catalog; publish keeps it current and 'orbit index' rebuilds it. Installs never use it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2026319f61
commit
4271a084b6
7 files changed
+498
-25
No files matched your search
+39
-16
@@ -867,13 +867,50 @@ fn print_table(rows : Array[Array[String]]) -> Unit {
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// Registry text for the terminal: control characters become spaces.
|
||||
fn printable(s : String) -> String {
|
||||
let sb = StringBuilder()
|
||||
for c in s {
|
||||
let n = c.to_int()
|
||||
sb.write_char(if n < 32 || (n >= 127 && n < 160) { ' ' } else { c })
|
||||
}
|
||||
sb.to_string()
|
||||
}
|
||||
|
||||
///|
|
||||
async fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
||||
let rows : Array[Array[String]] = [
|
||||
["PACKAGE", "CHANNEL", "VERSION", "DESCRIPTION"],
|
||||
]
|
||||
let mut listed = 0
|
||||
let add = fn(name : String, ch : Channel, version : String, desc : String) {
|
||||
rows.push([
|
||||
name,
|
||||
ch.name,
|
||||
if version == "" { "-" } else { printable(version) },
|
||||
if desc == "" { "-" } else { printable(desc) },
|
||||
])
|
||||
}
|
||||
let term_lower = ascii_lower(term)
|
||||
for ch in ctx.channels {
|
||||
// Without a usable index, ask the registry's catalog.
|
||||
let index = load_index(ch) catch {
|
||||
OrbitError(msg) => {
|
||||
println("warning: cannot read index of channel '\{ch.name}': \{msg}")
|
||||
None
|
||||
}
|
||||
}
|
||||
if index is Some(entries) {
|
||||
listed = listed + 1
|
||||
for e in entries {
|
||||
if contains_str(e.name, term_lower) ||
|
||||
contains_str(ascii_lower(e.description), term_lower) {
|
||||
add(e.name, ch, e.version, e.description)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
let repos = list_repos(ch) catch {
|
||||
OrbitError(msg) => {
|
||||
println("warning: cannot list channel '\{ch.name}': \{msg}")
|
||||
@@ -885,28 +922,14 @@ async fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
||||
for r in repos {
|
||||
// A name with "/" is a nested channel namespace (e.g. example/greet under
|
||||
// main), not a package name that `orbit install` could use.
|
||||
if valid_name(r) && contains_str(r, term) {
|
||||
if valid_name(r) && r != INDEX_NAME && contains_str(r, term_lower) {
|
||||
candidates.push(r)
|
||||
}
|
||||
}
|
||||
let found = find_orbit_repos(ch, candidates)
|
||||
for i, r in candidates {
|
||||
match found[i] {
|
||||
Some(info) =>
|
||||
rows.push([
|
||||
r,
|
||||
ch.name,
|
||||
if info.version == "" {
|
||||
"-"
|
||||
} else {
|
||||
info.version
|
||||
},
|
||||
if info.description == "" {
|
||||
"-"
|
||||
} else {
|
||||
info.description
|
||||
},
|
||||
])
|
||||
Some(info) => add(r, ch, info.version, info.description)
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user