92 lines
2.4 KiB
Rust
92 lines
2.4 KiB
Rust
use crate::{common::format_size, error};
|
|
use clap::Parser;
|
|
use packie::{
|
|
PackieBuilder,
|
|
local::Installation,
|
|
package::{PkgManifest, PkgSpec},
|
|
};
|
|
use rust_i18n::t;
|
|
use std::fmt::Write;
|
|
|
|
#[derive(Debug, Parser)]
|
|
pub struct Cli {
|
|
pkgspec: PkgSpec,
|
|
}
|
|
|
|
pub fn main(cli: Cli) -> Result<(), crate::Error> {
|
|
let mut packie = PackieBuilder::new().readonly(true).build()?;
|
|
let mut found = packie.search_installation(&cli.pkgspec)?;
|
|
if found.len() == 0 {
|
|
return Err(error!("info.no_package_found"));
|
|
}
|
|
if found.len() != 1 {
|
|
let mut note = String::new();
|
|
writeln!(&mut note, "{}", t!("info.note_pkgspec_not_unique")).unwrap();
|
|
for i in found.iter() {
|
|
writeln!(&mut note, " - {}", i.pkg_manifest.pkg_ident()).unwrap();
|
|
}
|
|
|
|
return Err(crate::Error {
|
|
message: t!("info.error_pkgspec_not_unique").into(),
|
|
note: Some(note),
|
|
});
|
|
}
|
|
let found = found.remove(0);
|
|
|
|
print_pkgmanifest(&found.pkg_manifest);
|
|
print_install_misc(&found);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn print_pkgmanifest(pkg_manifest: &PkgManifest) {
|
|
println!(
|
|
"{}: {}",
|
|
t!("info.print_pkgmanifest.name"),
|
|
pkg_manifest.name
|
|
);
|
|
println!(
|
|
"{}: {}",
|
|
t!("info.print_pkgmanifest.version"),
|
|
pkg_manifest.version
|
|
);
|
|
println!(
|
|
"{}: {}",
|
|
t!("info.print_pkgmanifest.arch"),
|
|
pkg_manifest.arch
|
|
);
|
|
if !pkg_manifest.description.is_empty() {
|
|
println!(
|
|
"{}: {}",
|
|
t!("info.print_pkgmanifest.description"),
|
|
pkg_manifest.arch
|
|
);
|
|
}
|
|
println!("{}:", t!("info.print_pkgmanifest.dependencies"));
|
|
for i in pkg_manifest.dependencies.iter() {
|
|
println!(" - {i}");
|
|
}
|
|
println!("{}:", t!("info.print_pkgmanifest.recommendations"));
|
|
for i in pkg_manifest.recommendations.iter() {
|
|
println!(" - {i}");
|
|
}
|
|
}
|
|
|
|
fn print_install_misc(installation: &Installation) {
|
|
println!(
|
|
"{}: {}",
|
|
t!("info.print_install_misc.install_pkgspec"),
|
|
installation.install_pkgspec
|
|
);
|
|
println!(
|
|
"{}: {}",
|
|
t!("info.print_install_misc.install_date"),
|
|
crate::common::format_datetime(installation.install_date),
|
|
);
|
|
println!(
|
|
"{}: {}",
|
|
t!("info.print_install_misc.installed_size"),
|
|
format_size(installation.installed_size),
|
|
);
|
|
}
|