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