Show info for packages that aren't installed
- `orbit info` finds a package that isn't installed, or a `channel::` / `@constraint` build, in the cached channel listings used by search - Channel indexes record each version's manifest digest, so a repeated info needs no network - Versions without a digest, or indexes built before digests were added, are resolved in the registry - Show the docs link, channel, digest, bins and dependencies for available builds
This commit is contained in:
1 parent
022898ed65
commit
a00c87bf04
7 files changed
+176
-29
No files matched your search
@@ -61,6 +61,36 @@ fn package_details(
|
||||
]
|
||||
}
|
||||
|
||||
///|
|
||||
/// The details of a build in a channel that isn't installed: it has no paths
|
||||
/// yet, so bins are shown as they sit in the package.
|
||||
fn available_details(
|
||||
m : Manifest,
|
||||
channel~ : String,
|
||||
digest~ : String,
|
||||
) -> Array[Detail] {
|
||||
let bins = m.bins.copy()
|
||||
if bins.is_empty() {
|
||||
bins.push("(none)")
|
||||
}
|
||||
let specs = fn(reqs : Map[String, String]) {
|
||||
let out : Array[String] = []
|
||||
for n, c in reqs {
|
||||
out.push(n + "@" + c)
|
||||
}
|
||||
join(out, " ")
|
||||
}
|
||||
[
|
||||
("description", [m.description]),
|
||||
("docs", [m.documentation]),
|
||||
("channel", [channel]),
|
||||
("digest", [digest]),
|
||||
("bin", bins),
|
||||
("depends", [specs(m.depends)]),
|
||||
("conflicts", [specs(m.conflicts)]),
|
||||
]
|
||||
}
|
||||
|
||||
///|
|
||||
fn installed_details(ctx : Ctx, p : Installed) -> Array[Detail] {
|
||||
package_details(
|
||||
@@ -116,3 +146,17 @@ test "package details show paths and every bin" {
|
||||
"bin: (none)",
|
||||
])
|
||||
}
|
||||
|
||||
///|
|
||||
test "available details show bins as packaged and the docs link" {
|
||||
let m = parse_manifest(
|
||||
"{\"name\":\"t\",\"version\":\"1.0.0\",\"description\":\"A tool\",\"documentation\":\"https://x/t\",\"bin\":[\"bin/a\"],\"depends\":{\"x\":\"^1\"}}",
|
||||
)
|
||||
assert_eq(
|
||||
detail_lines(available_details(m, channel="main", digest="sha256:ab"), ""),
|
||||
[
|
||||
"description: A tool", "docs: https://x/t", "channel: main", "digest: sha256:ab",
|
||||
"bin: bin/a", "depends: x@^1",
|
||||
],
|
||||
)
|
||||
}
|
||||
+21
-2
@@ -20,6 +20,7 @@ struct IndexEntry {
|
||||
version : String
|
||||
description : String
|
||||
versions : Array[String] // newest first
|
||||
digest : String // of the `version` manifest; "" in older indexes
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -33,6 +34,9 @@ fn index_object(entries : Array[IndexEntry]) -> Map[String, Json] {
|
||||
o["version"] = Json::string(e.version)
|
||||
o["description"] = Json::string(e.description)
|
||||
o["versions"] = strs_json(e.versions)
|
||||
if e.digest != "" {
|
||||
o["digest"] = Json::string(e.digest)
|
||||
}
|
||||
pkgs.push(Json::object(o))
|
||||
}
|
||||
let top : Map[String, Json] = Map([])
|
||||
@@ -64,6 +68,7 @@ fn parse_index(text : String) -> Array[IndexEntry] raise OrbitError {
|
||||
version: jstr(o, "version", ""),
|
||||
description: jstr(o, "description", ""),
|
||||
versions: jstrs(o, "versions"),
|
||||
digest: jstr(o, "digest", ""),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -186,13 +191,15 @@ async fn read_index_entry(
|
||||
return None
|
||||
}
|
||||
let tag = if tags.contains("latest") { "latest" } else { tags[0] }
|
||||
match orbit_info(fetch_raw_manifest(ch, name, tag)) {
|
||||
let raw = fetch_raw_manifest_bytes(ch, name, tag)
|
||||
match orbit_info(utf8_decode(raw)) {
|
||||
Some(info) =>
|
||||
Some(IndexEntry::{
|
||||
name,
|
||||
version: info.version,
|
||||
description: info.description,
|
||||
versions: sorted_versions(tags),
|
||||
digest: sha256_digest(raw),
|
||||
})
|
||||
None => None
|
||||
}
|
||||
@@ -334,7 +341,13 @@ async fn index_published(ch : Channel, name : String) -> Unit noraise {
|
||||
///|
|
||||
test "index round-trips, sorted, without unusable names" {
|
||||
let entry = fn(name : String) {
|
||||
IndexEntry::{ name, version: "1.0.0", description: "d", versions: ["1.0.0"] }
|
||||
IndexEntry::{
|
||||
name,
|
||||
version: "1.0.0",
|
||||
description: "d",
|
||||
versions: ["1.0.0"],
|
||||
digest: "sha256:ab",
|
||||
}
|
||||
}
|
||||
let parsed = parse_index(
|
||||
index_json([
|
||||
@@ -346,6 +359,12 @@ test "index round-trips, sorted, without unusable names" {
|
||||
)
|
||||
assert_eq(parsed.map(fn(e) { e.name }), ["a", "zed"])
|
||||
assert_eq(parsed[0].versions, ["1.0.0"])
|
||||
assert_eq(parsed[0].digest, "sha256:ab")
|
||||
// Indexes written before digests were recorded still parse.
|
||||
let old = parse_index(
|
||||
"{\"packages\":[{\"name\":\"a\",\"version\":\"1.0.0\",\"description\":\"d\",\"versions\":[\"1.0.0\"]}]}",
|
||||
)
|
||||
assert_eq(old[0].digest, "")
|
||||
// Only an index artifact is used, and it is not an Orbit package.
|
||||
assert_true(index_layer_digest("{\"artifactType\":\"x\"}") is None)
|
||||
assert_true(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Local copies of channel listings, so that a repeated search needs no network.
|
||||
// Installs and version lookups never read them.
|
||||
// Local copies of channel listings, so that a repeated search or info needs no
|
||||
// network. Installs and version lookups never read them.
|
||||
|
||||
///|
|
||||
/// How long a copy is used before it is fetched again.
|
||||
@@ -91,7 +91,8 @@ async fn drop_cached_indexes(root : String) -> Unit noraise {
|
||||
}
|
||||
|
||||
///|
|
||||
/// A channel's packages for search, which still has to match `term`: a fresh
|
||||
/// A channel's packages for search and info, which still have to match `term`
|
||||
/// (a large channel without an index only lists those that do): a fresh
|
||||
/// copy, else its index, else the registry's catalog. If the registry fails, an
|
||||
/// old copy is used. None means the channel couldn't be listed.
|
||||
async fn channel_listing(
|
||||
@@ -177,6 +178,7 @@ async fn list_catalog(
|
||||
version: info.version,
|
||||
description: info.description,
|
||||
versions: [],
|
||||
digest: "",
|
||||
})
|
||||
None => ()
|
||||
}
|
||||
|
||||
+4
-3
@@ -41,8 +41,9 @@ let usage : String =
|
||||
#| orbit upgrade [-g] [name...] jointly upgrade within constraints
|
||||
#| orbit rollback <name> switch to the previous global build
|
||||
#| orbit list [-g] installed global packages
|
||||
#| orbit info [-g] [channel::]<name> details of an installed package: paths,
|
||||
#| bins, dependencies (local only)
|
||||
#| orbit info [-g] [channel::]<name>[@constraint]
|
||||
#| details of an installed package, else of
|
||||
#| the newest matching build in a channel
|
||||
#| orbit versions <name> published versions
|
||||
#| orbit search [--refresh] [term] list packages (cached for an hour)
|
||||
#| orbit gc delete unused builds from the store
|
||||
@@ -349,7 +350,7 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
||||
None => cmd_list(load_ctx())
|
||||
}
|
||||
"info" => {
|
||||
need(pos, 1, "info [channel::]<name>")
|
||||
need(pos, 1, "info [channel::]<name>[@constraint]")
|
||||
match resolve_project_or_none(force_global, manifest_path) {
|
||||
Some(mf) => cmd_project_info(load_ctx(), mf, pos[0])
|
||||
None => cmd_info(load_ctx(), pos[0])
|
||||
|
||||
+86
-17
@@ -764,25 +764,94 @@ async fn locate_spec(
|
||||
}
|
||||
|
||||
///|
|
||||
fn cmd_info(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
||||
let (pin, name) = split_channel(spec)
|
||||
let p = match ctx.state.get(name) {
|
||||
Some(p) => p
|
||||
None => raise OrbitError("\{spec} is not installed")
|
||||
/// Find a build for info in the channel listings that search caches: the
|
||||
/// pinned channel, else the one it is installed from, else by priority. None
|
||||
/// if no listing has a matching version with a known digest, so the registry
|
||||
/// has to be asked.
|
||||
async fn listed_build(
|
||||
ctx : Ctx,
|
||||
name : String,
|
||||
pin : String?,
|
||||
constraint : String,
|
||||
) -> (Channel, String, String)? raise OrbitError {
|
||||
let wanted = match pin {
|
||||
Some(c) => Some(c)
|
||||
None => ctx.state.get(name).map(i => i.channel)
|
||||
}
|
||||
if pin is Some(channel) && channel != p.channel {
|
||||
raise OrbitError("\{spec} is not installed (installed from '\{p.channel}')")
|
||||
let channels = match wanted {
|
||||
Some(c) => [find_channel(ctx, c)]
|
||||
None => ctx.channels
|
||||
}
|
||||
println("\{name} \{p.version} (installed)")
|
||||
print_details(installed_details(ctx, p), " ")
|
||||
print_details(
|
||||
[
|
||||
("constraint", [p.constraint]),
|
||||
("needed by", [join(reverse_deps(ctx, name), " ")]),
|
||||
("rollback", [join(p.history.map(g => g.version), " ")]),
|
||||
],
|
||||
" ",
|
||||
)
|
||||
for ch in channels {
|
||||
let entries = match channel_listing(ctx.root, ch, name, false) {
|
||||
Some(es) => es
|
||||
None => continue
|
||||
}
|
||||
match find_entry(entries, name) {
|
||||
Some(e) =>
|
||||
if e.digest != "" && satisfies_all(e.version, [constraint]) {
|
||||
return Some((ch, e.version, e.digest))
|
||||
} else {
|
||||
// Another version, or no digest: the registry knows its digest.
|
||||
return None
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
///|
|
||||
/// Details of an installed package, or of the newest matching build in a
|
||||
/// channel when it isn't installed (or `channel::` / `@constraint` asks for
|
||||
/// another build).
|
||||
async fn cmd_info(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
||||
let (pin, name, constraint, explicit) = parse_spec_full(spec)
|
||||
match ctx.state.get(name) {
|
||||
Some(p) =>
|
||||
if (pin is None || pin == Some(p.channel)) &&
|
||||
(!explicit || satisfies_all(p.version, [constraint])) {
|
||||
println("\{name} \{p.version} (installed)")
|
||||
print_details(installed_details(ctx, p), " ")
|
||||
print_details(
|
||||
[
|
||||
("constraint", [p.constraint]),
|
||||
("needed by", [join(reverse_deps(ctx, name), " ")]),
|
||||
("rollback", [join(p.history.map(g => g.version), " ")]),
|
||||
],
|
||||
" ",
|
||||
)
|
||||
return
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
let (ch, version, digest) = match listed_build(ctx, name, pin, constraint) {
|
||||
Some(found) => found
|
||||
None => {
|
||||
let wanted = match pin {
|
||||
Some(c) => Some(c)
|
||||
None => ctx.state.get(name).map(i => i.channel)
|
||||
}
|
||||
let (ch, tags) = locate(ctx, name, wanted)
|
||||
let versions = sorted_versions(tags)
|
||||
let version = match
|
||||
versions.search_by(v => satisfies_all(v, [constraint])) {
|
||||
Some(i) => versions[i]
|
||||
None =>
|
||||
raise OrbitError(
|
||||
"no version of \{ch.name}::\{name} matches '\{constraint}'",
|
||||
)
|
||||
}
|
||||
(ch, version, resolve_digest(ch, name, version))
|
||||
}
|
||||
}
|
||||
let m = fetch_manifest_cached(ctx.root, ch, name, digest)
|
||||
let status = match ctx.state.get(name) {
|
||||
Some(p) => "not installed; \{p.version} from \{p.channel} is"
|
||||
None => "not installed"
|
||||
}
|
||||
println("\{name} \{version} (\{status})")
|
||||
print_details(available_details(m, channel=ch.name, digest~), " ")
|
||||
}
|
||||
|
||||
///|
|
||||
|
||||
Reference in new issue
Block a user