Show package details on install
Installs, syncs and upgrades print each new build's paths, bins and dependencies. orbit info prints the same, also for a project's packages. Planning: y4x2r Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cc47acb3e2
commit
abd0dfca1e
6 files changed
+209
-32
No files matched your search
@@ -0,0 +1,118 @@
|
||||
// What install and info print about a package.
|
||||
|
||||
///|
|
||||
/// Label and values. Each value after the first gets its own line.
|
||||
type Detail = (String, Array[String])
|
||||
|
||||
///|
|
||||
/// Align details in columns, dropping empty ones. Values may come from a
|
||||
/// registry, so control characters are blanked.
|
||||
fn detail_lines(details : Array[Detail], indent : String) -> Array[String] {
|
||||
let lines : Array[String] = []
|
||||
for detail in details {
|
||||
let (label, values) = detail
|
||||
let mut head = label + ":"
|
||||
for v in values {
|
||||
if v != "" {
|
||||
lines.push(indent + pad_right(head, 13) + printable(v))
|
||||
head = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
lines
|
||||
}
|
||||
|
||||
///|
|
||||
fn print_details(details : Array[Detail], indent : String) -> Unit {
|
||||
for line in detail_lines(details, indent) {
|
||||
println(line)
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// The details of a build that install and info share. `bin_dir` is where its
|
||||
/// commands are linked, `store` where its files are.
|
||||
fn package_details(
|
||||
m : Manifest,
|
||||
channel~ : String,
|
||||
digest~ : String,
|
||||
store~ : String,
|
||||
bin_dir~ : String,
|
||||
) -> Array[Detail] {
|
||||
let bins = m.bins.map(b => bin_dir + "/" + basename(b) + " -> " + b)
|
||||
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]),
|
||||
("channel", [channel]),
|
||||
("digest", [digest]),
|
||||
("path", [store]),
|
||||
("bin", bins),
|
||||
("depends", [specs(m.depends)]),
|
||||
("conflicts", [specs(m.conflicts)]),
|
||||
]
|
||||
}
|
||||
|
||||
///|
|
||||
fn installed_details(ctx : Ctx, p : Installed) -> Array[Detail] {
|
||||
package_details(
|
||||
manifest_of_installed(p),
|
||||
channel=p.channel,
|
||||
digest=p.digest,
|
||||
store=store_dir(ctx, p.name, p.digest),
|
||||
bin_dir=bin_dir(ctx),
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
fn locked_details(
|
||||
ctx : Ctx,
|
||||
project_dir : String,
|
||||
p : LockedPkg,
|
||||
) -> Array[Detail] {
|
||||
package_details(
|
||||
manifest_of_locked(p),
|
||||
channel=p.channel,
|
||||
digest=p.digest,
|
||||
store=store_dir(ctx, p.name, p.digest),
|
||||
bin_dir=project_env_dir(project_dir) + "/bin",
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
test "package details show paths and every bin" {
|
||||
let m = parse_manifest(
|
||||
"{\"name\":\"t\",\"version\":\"1.0.0\",\"description\":\"A\\u001btool\",\"bin\":[\"bin/a\",\"libexec/b\"],\"depends\":{\"x\":\"^1\"},\"conflicts\":{\"y\":\"*\"}}",
|
||||
)
|
||||
let details = package_details(
|
||||
m,
|
||||
channel="main",
|
||||
digest="sha256:ab",
|
||||
store="/o/store/t/ab",
|
||||
bin_dir="/o/bin",
|
||||
)
|
||||
assert_eq(detail_lines(details, " "), [
|
||||
" description: A tool", " channel: main", " digest: sha256:ab", " path: /o/store/t/ab",
|
||||
" bin: /o/bin/a -> bin/a", " /o/bin/b -> libexec/b", " depends: x@^1",
|
||||
" conflicts: y@*",
|
||||
])
|
||||
let bare = package_details(
|
||||
parse_manifest("{\"name\":\"t\",\"version\":\"1.0.0\"}"),
|
||||
channel="main",
|
||||
digest="sha256:ab",
|
||||
store="/o/store/t/ab",
|
||||
bin_dir="/o/bin",
|
||||
)
|
||||
assert_eq(detail_lines(bare, ""), [
|
||||
"channel: main", "digest: sha256:ab", "path: /o/store/t/ab",
|
||||
"bin: (none)",
|
||||
])
|
||||
}
|
||||
+6
-2
@@ -41,7 +41,8 @@ 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 [channel::]<name> installed package details (local only)
|
||||
#| orbit info [-g] [channel::]<name> details of an installed package: paths,
|
||||
#| bins, dependencies (local only)
|
||||
#| 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,10 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
||||
}
|
||||
"info" => {
|
||||
need(pos, 1, "info [channel::]<name>")
|
||||
cmd_info(load_ctx(), pos[0])
|
||||
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])
|
||||
}
|
||||
}
|
||||
"versions" => {
|
||||
need(pos, 1, "versions <name>")
|
||||
|
||||
+10
-26
@@ -384,6 +384,7 @@ async fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
link_bins(ctx, dir, st.manifest.bins)
|
||||
// Persist after each package so a later failure leaves accurate state.
|
||||
save_state(ctx)
|
||||
print_details(installed_details(ctx, ctx.state[st.name]), " ")
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -765,32 +766,15 @@ fn cmd_info(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
||||
raise OrbitError("\{spec} is not installed (installed from '\{p.channel}')")
|
||||
}
|
||||
println("\{name} \{p.version} (installed)")
|
||||
if p.description != "" {
|
||||
println(" description: \{p.description}")
|
||||
}
|
||||
println(" channel: \{p.channel}")
|
||||
println(" digest: \{p.digest}")
|
||||
println(" constraint: \{p.constraint}")
|
||||
println(" bin: \{join(p.bins, " ")}")
|
||||
let deps : Array[String] = []
|
||||
for d, c in p.depends {
|
||||
deps.push(d + "@" + c)
|
||||
}
|
||||
println(" depends: \{join(deps, " ")}")
|
||||
if !p.conflicts.is_empty() {
|
||||
let cs : Array[String] = []
|
||||
for n, c in p.conflicts {
|
||||
cs.push(n + "@" + c)
|
||||
}
|
||||
println(" conflicts: \{join(cs, " ")}")
|
||||
}
|
||||
let rd = reverse_deps(ctx, name)
|
||||
println(" needed by: \{join(rd, " ")}")
|
||||
let hist : Array[String] = []
|
||||
for g in p.history {
|
||||
hist.push(g.version)
|
||||
}
|
||||
println(" rollback: \{join(hist, " ")}")
|
||||
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), " ")]),
|
||||
],
|
||||
" ",
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
|
||||
+62
-3
@@ -1065,6 +1065,7 @@ async fn sync_project_env(
|
||||
root : String,
|
||||
project_dir : String,
|
||||
lock : Lockfile,
|
||||
show? : Bool = false,
|
||||
) -> Int32 raise OrbitError {
|
||||
let bin_owners : Map[String, String] = Map([])
|
||||
for lp in lock.packages {
|
||||
@@ -1155,6 +1156,14 @@ async fn sync_project_env(
|
||||
}
|
||||
}
|
||||
write_text_atomic(env_path, env_json_text(desired_pkgs))
|
||||
if show {
|
||||
for lp in lock.packages {
|
||||
if prev_pkgs.get(lp.name) != Some(lp.digest) {
|
||||
println(" \{lp.name} \{lp.version} installed")
|
||||
print_details(locked_details(store_ctx, project_dir, lp), " ")
|
||||
}
|
||||
}
|
||||
}
|
||||
if changed == 0 {
|
||||
1
|
||||
} else {
|
||||
@@ -1272,7 +1281,7 @@ async fn ensure_project_synced(
|
||||
solved
|
||||
}
|
||||
}
|
||||
let synced = sync_project_env(ctx.root, project_dir, lock)
|
||||
let synced = sync_project_env(ctx.root, project_dir, lock, show=!quiet)
|
||||
if !quiet {
|
||||
if synced == 0 {
|
||||
println("environment is up to date")
|
||||
@@ -1351,7 +1360,7 @@ async fn cmd_project_add(
|
||||
ignore(parse_project_manifest(updated_toml, m.name))
|
||||
write_text_atomic(manifest_file, updated_toml)
|
||||
write_text_atomic(lock_path, lockfile_to_toml(lock))
|
||||
ignore(sync_project_env(ctx.root, project_dir, lock))
|
||||
ignore(sync_project_env(ctx.root, project_dir, lock, show=true))
|
||||
for name in added_names {
|
||||
match solved_by_name.get(name) {
|
||||
Some(lp) =>
|
||||
@@ -1426,7 +1435,7 @@ async fn cmd_project_update(
|
||||
upgrade_all,
|
||||
)
|
||||
write_text_atomic(lock_path, lockfile_to_toml(lock))
|
||||
let synced = sync_project_env(ctx.root, project_dir, lock)
|
||||
let synced = sync_project_env(ctx.root, project_dir, lock, show=true)
|
||||
if synced == 0 {
|
||||
println("already up to date")
|
||||
} else {
|
||||
@@ -1557,6 +1566,56 @@ async fn cmd_project_list(
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// Details of a package in the project's lockfile, or else of a global one.
|
||||
async fn cmd_project_info(
|
||||
ctx : Ctx,
|
||||
manifest_file : String,
|
||||
spec : String,
|
||||
) -> Unit raise OrbitError {
|
||||
let (project_dir, m, _) = load_project(manifest_file, ctx.channels)
|
||||
let (pin, name) = split_channel(spec)
|
||||
let packages = match read_existing_lock(project_dir + "/orbit.lock") {
|
||||
Some(lock) => lock.packages
|
||||
None => []
|
||||
}
|
||||
for p in packages {
|
||||
if p.name != name || (pin is Some(channel) && channel != p.channel) {
|
||||
continue
|
||||
}
|
||||
let env = match read_text(project_env_dir(project_dir) + "/env.json") {
|
||||
Some(t) => read_env_packages(t)
|
||||
None => Map([])
|
||||
}
|
||||
let status = if env.get(name) == Some(p.digest) {
|
||||
"installed in \{m.name}"
|
||||
} else {
|
||||
"locked in \{m.name}, not installed"
|
||||
}
|
||||
println("\{name} \{p.version} (\{status})")
|
||||
print_details(locked_details(ctx, project_dir, p), " ")
|
||||
let constraint = match m.dependencies.get(name) {
|
||||
Some(d) => d.constraint
|
||||
None => ""
|
||||
}
|
||||
let users : Array[String] = []
|
||||
for other in packages {
|
||||
for dep, _ in other.depends {
|
||||
if parse_dep_key(dep).1 == name {
|
||||
users.push(other.name)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
print_details(
|
||||
[("constraint", [constraint]), ("needed by", [join(users, " ")])],
|
||||
" ",
|
||||
)
|
||||
return
|
||||
}
|
||||
cmd_info(ctx, spec)
|
||||
}
|
||||
|
||||
///|
|
||||
fn cmd_project_env(ctx : Ctx, manifest_file : String) -> Unit {
|
||||
let project_dir = path_dirname(manifest_file)
|
||||
|
||||
Reference in new issue
Block a user