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