180 lines
5.0 KiB
Rust
180 lines
5.0 KiB
Rust
use crate::{common::format_size, error};
|
|
use clap::Parser;
|
|
use console::style;
|
|
use packie::{
|
|
PackieBuilder,
|
|
local::LocalPackage,
|
|
package::{PkgManifest, PkgSpec},
|
|
repo::RepoPackage,
|
|
};
|
|
use rust_i18n::t;
|
|
use std::collections::HashMap;
|
|
|
|
#[derive(Debug, Parser)]
|
|
pub struct Cli {
|
|
/// Search only local-installed packages, even if remote packages are available
|
|
#[arg(short, long)]
|
|
local_only: bool,
|
|
|
|
pkgspec: PkgSpec,
|
|
}
|
|
|
|
pub fn main(cli: Cli) -> Result<(), crate::Error> {
|
|
let mut packie = PackieBuilder::new().readonly(true).build()?;
|
|
|
|
let mut everything = HashMap::new();
|
|
|
|
let remote = if cli.local_only {
|
|
Vec::new()
|
|
} else {
|
|
packie.query_repo().search_package(&cli.pkgspec)
|
|
};
|
|
for i in remote {
|
|
everything.insert(
|
|
i.pkg_manifest.pkg_ident(),
|
|
ComprehensivePackageInfo::from(i),
|
|
);
|
|
}
|
|
|
|
let local = packie.search_local_package(&cli.pkgspec)?;
|
|
for i in local {
|
|
let val = everything
|
|
.entry(i.pkg_manifest.pkg_ident())
|
|
.or_insert_with(|| ComprehensivePackageInfo::from(i.clone()));
|
|
val.installed = true;
|
|
val.installed_size = i.installed_size;
|
|
val.install_date = Some(i.install_date);
|
|
}
|
|
|
|
if everything.is_empty() {
|
|
return Err(error!("info.no_package_found"));
|
|
}
|
|
|
|
for i in everything.values() {
|
|
print_info(&i);
|
|
println!();
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
struct ComprehensivePackageInfo {
|
|
pkg_manifest: PkgManifest,
|
|
installed: bool,
|
|
install_pkgspec: Option<PkgSpec>,
|
|
install_date: Option<i64>,
|
|
download_size: Option<u64>,
|
|
installed_size: u64,
|
|
auto_installed: Option<bool>,
|
|
}
|
|
impl From<RepoPackage> for ComprehensivePackageInfo {
|
|
fn from(value: RepoPackage) -> Self {
|
|
Self {
|
|
pkg_manifest: value.pkg_manifest,
|
|
installed: false,
|
|
install_pkgspec: None,
|
|
install_date: None,
|
|
download_size: Some(value.download_size),
|
|
installed_size: value.installed_size,
|
|
auto_installed: None,
|
|
}
|
|
}
|
|
}
|
|
impl From<LocalPackage> for ComprehensivePackageInfo {
|
|
fn from(value: LocalPackage) -> Self {
|
|
Self {
|
|
pkg_manifest: value.pkg_manifest,
|
|
installed: true,
|
|
install_pkgspec: None,
|
|
install_date: Some(value.install_date),
|
|
download_size: None,
|
|
installed_size: value.installed_size,
|
|
auto_installed: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
fn print_info(info: &ComprehensivePackageInfo) {
|
|
if info.installed {
|
|
println!(
|
|
"+ {} [{}]",
|
|
style(info.pkg_manifest.pkg_ident()).green(),
|
|
t!("info.print_info.installed"),
|
|
);
|
|
} else {
|
|
println!("+ {}", style(info.pkg_manifest.pkg_ident()).green());
|
|
}
|
|
println!(
|
|
" {}: {}",
|
|
t!("info.print_info.name"),
|
|
info.pkg_manifest.name
|
|
);
|
|
println!(
|
|
" {}: {}",
|
|
t!("info.print_info.version"),
|
|
info.pkg_manifest.version
|
|
);
|
|
println!(
|
|
" {}: {}",
|
|
t!("info.print_info.arch"),
|
|
info.pkg_manifest.arch
|
|
);
|
|
if !info.pkg_manifest.description.is_empty() {
|
|
println!(
|
|
" {}: {}",
|
|
t!("info.print_info.description"),
|
|
info.pkg_manifest.description
|
|
);
|
|
}
|
|
if let Some(license) = &info.pkg_manifest.license {
|
|
println!(" {}: {}", t!("info.print_info.license"), license);
|
|
}
|
|
if !info.pkg_manifest.maintainers.is_empty() {
|
|
println!(" {}:", t!("info.print_info.maintainers"));
|
|
for i in info.pkg_manifest.maintainers.iter() {
|
|
println!(" - {i}");
|
|
}
|
|
}
|
|
if !info.pkg_manifest.dependencies.is_empty() {
|
|
println!(" {}:", t!("info.print_info.dependencies"));
|
|
for i in info.pkg_manifest.dependencies.iter() {
|
|
println!(" - {i}");
|
|
}
|
|
}
|
|
if !info.pkg_manifest.recommendations.is_empty() {
|
|
println!(" {}:", t!("info.print_info.recommendations"));
|
|
for i in info.pkg_manifest.recommendations.iter() {
|
|
println!(" - {i}");
|
|
}
|
|
}
|
|
if let Some(pkgspec) = &info.install_pkgspec {
|
|
println!(" {}: {pkgspec}", t!("info.print_info.install_pkgspec"));
|
|
}
|
|
if let Some(install_date) = &info.install_date {
|
|
println!(
|
|
" {}: {}",
|
|
t!("info.print_info.install_date"),
|
|
crate::common::format_datetime(*install_date),
|
|
);
|
|
}
|
|
if let Some(download_size) = &info.download_size {
|
|
println!(
|
|
" {}: {}",
|
|
t!("info.print_info.download_size"),
|
|
format_size(*download_size as _),
|
|
);
|
|
}
|
|
println!(
|
|
" {}: {}",
|
|
t!("info.print_info.installed_size"),
|
|
format_size(info.installed_size as _),
|
|
);
|
|
if let Some(auto_installed) = info.auto_installed {
|
|
println!(
|
|
" {}: {auto_installed}",
|
|
t!("info.print_info.auto_installed")
|
|
);
|
|
}
|
|
}
|