Skip to main content

lux_cli/
info.rs

1use clap::Args;
2use lux_lib::{
3    config::Config, operations::Download, package::PackageReq, rockspec::Rockspec,
4    tree::InstallTree,
5};
6
7use miette::Result;
8
9use crate::workspace::current_workspace_or_user_tree;
10
11#[derive(Args)]
12pub struct Info {
13    package: PackageReq,
14}
15
16pub async fn info(data: Info, config: Config) -> Result<()> {
17    let tree = current_workspace_or_user_tree(&config)?;
18
19    let rockspec = Download::new(&data.package, &config)
20        .download_rockspec()
21        .await?
22        .rockspec;
23
24    if tree.match_rocks(&data.package)?.is_found() {
25        println!("Currently installed in {}", tree.root().display());
26    }
27
28    println!("Package name: {}", rockspec.package());
29    println!("Package version: {}", rockspec.version());
30    println!();
31
32    println!(
33        "Summary: {}",
34        rockspec
35            .description()
36            .summary
37            .as_ref()
38            .unwrap_or(&"None".to_string())
39    );
40    println!(
41        "Description: {}",
42        rockspec
43            .description()
44            .detailed
45            .as_ref()
46            .unwrap_or(&"None".to_string())
47            .trim()
48    );
49    println!(
50        "License: {}",
51        rockspec
52            .description()
53            .license
54            .as_ref()
55            .unwrap_or(&"Unknown (all rights reserved by the author)".to_string())
56    );
57    println!(
58        "Maintainer: {}",
59        rockspec
60            .description()
61            .maintainer
62            .as_ref()
63            .unwrap_or(&"Unspecified".to_string())
64    );
65
66    Ok(())
67}