Skip to main content

rbnx/cmd/
info.rs

1// SPDX-License-Identifier: MulanPSL-2.0
2// Info command: show details of a system-installed package
3
4use anyhow::{Context, Result};
5use robonix_cli::output;
6use robonix_cli::{Config, PackageDatabase, PackageSource};
7
8pub async fn execute(config: Config, name: &str) -> Result<()> {
9    config.ensure_storage_dir()?;
10    let db = PackageDatabase::load(&config.package_storage_path)?;
11
12    let pkg = db
13        .get_package(name)
14        .with_context(|| format!("Package '{}' not found", name))?;
15
16    output::action("Package", &pkg.name);
17    output::sub_step(&format!("Version: {}", pkg.version));
18    output::sub_step(&format!("Path: {}", pkg.path.display()));
19    output::sub_step(&format!("Installed: {}", pkg.installed_at));
20
21    match &pkg.source {
22        PackageSource::Local { path } => {
23            output::sub_step(&format!("Source: local ({})", path.display()));
24        }
25        PackageSource::GitHub {
26            repo,
27            branch,
28            commit,
29        } => {
30            let branch_str = branch
31                .as_ref()
32                .map(|b| format!(" branch={}", b))
33                .unwrap_or_default();
34            output::sub_step(&format!(
35                "Source: GitHub {} (commit={}){}",
36                repo, commit, branch_str
37            ));
38        }
39    }
40
41    if !pkg.capabilities.is_empty() {
42        output::sub_step(&format!("Capabilities: {}", pkg.capabilities.join(", ")));
43    }
44    if !pkg.depends.is_empty() {
45        output::sub_step(&format!("Depends: {}", pkg.depends.join(", ")));
46    }
47
48    Ok(())
49}