diff --git a/manifest/src/package.rs b/manifest/src/package.rs index 233206d..d7c126c 100644 --- a/manifest/src/package.rs +++ b/manifest/src/package.rs @@ -12,6 +12,16 @@ pub enum PackageType { Meta, } +impl ToString for PackageType { + fn to_string(&self) -> String { + match &self { + PackageType::Application => "application", + PackageType::Library => "library", + PackageType::Meta => "meta" + }.to_string() + } +} + #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(default)] pub struct Package { diff --git a/pkgr/src/commands.rs b/pkgr/src/commands.rs index 87da700..31ae49c 100644 --- a/pkgr/src/commands.rs +++ b/pkgr/src/commands.rs @@ -4,6 +4,7 @@ use clap::{Parser, Subcommand}; use log::{debug, error, info, trace, warn}; use colored::Colorize; +use manifest::package::PackageType; use crate::CONFIG; use crate::package::identifier::PackageIdentifier; use crate::package::Package; @@ -40,10 +41,9 @@ pub enum Command { }, /// Update packages on the system Update, - /// Get info about pkgr + /// Get info about a package Info { - #[arg(short, long, default_value_t = false)] - detailed: bool + package_identifier: Option }, #[cfg(debug_assertions)] Debug, @@ -114,12 +114,34 @@ impl Command { error!("Update is not yet implemented."); } Command::Info { - detailed + package_identifier } => { - info!("Welcome to pkgr!\n\ - {}\n\ - To get help please run \"{} -h\"", env!("CARGO_PKG_DESCRIPTION"), std::env::args().nth(0).unwrap()); - if *detailed { + if let Some(p) = package_identifier { + if let Ok(mut pkg) = Package::try_fetch(p.clone()) { + info!(target: "item", "Identifier: {:?}", pkg.identifier); + info!(target: "item", ""); + let mani = pkg.manifest(); + info!(target: "item", "Package name: {}", mani.package.name); + info!(target: "item", "Package description: {}", mani.package.description); + info!(target: "item", "Package version: {}", mani.package.version); + info!(target: "item", "Package tags: {}", mani.package.tags.join(", ")); + info!(target: "item", "Package type: {}", mani.package.package_type.to_string()); + info!(target: "item", ""); + info!(target: "item", "Supported install types: {}", { + let mut types = vec![]; + if let Some(_) = mani.bin { types.push("bin") } + if let Some(_) = mani.build { types.push("build") } + if let PackageType::Meta = mani.package.package_type { types.push("meta") } + types.join(", ") + }); + info!(target: "item", ""); + } else { + error!("Could not find {p}"); + } + } else { + info!("Welcome to pkgr!\n\ + {}\n\ + To get help please run \"{} -h\"", env!("CARGO_PKG_DESCRIPTION"), std::env::args().nth(0).unwrap()); info!(""); info!("version: {}", env!("CARGO_PKG_VERSION")); info!("authors: {}", env!("CARGO_PKG_AUTHORS")); diff --git a/pkgr/src/package/mod.rs b/pkgr/src/package/mod.rs index a0c0fd0..96328f4 100644 --- a/pkgr/src/package/mod.rs +++ b/pkgr/src/package/mod.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use std::path::Path; -use log::info; +use log::{debug, info, trace}; use reqwest::blocking::get; use pkgfile::PKGFile; @@ -104,6 +104,7 @@ impl TryFetch for Package { /// Fetch a package from a package identifier. fn try_fetch(query: PackageIdentifier) -> Result { + trace!("Fetching: {query:#?}"); let pkgfile = match &query { PackageIdentifier::Path(s) => match PKGFile::try_from(Path::new(&s)) { Ok(p) => Ok(p), @@ -111,8 +112,10 @@ impl TryFetch for Package { }, PackageIdentifier::URI(s) => { let mut bytes = Vec::new(); + debug!("sending GET request..."); match get::(s.into()) { Ok(response) => { + debug!("Got response!"); if let Ok(b) = response.bytes() { bytes.extend(b); } @@ -125,7 +128,7 @@ impl TryFetch for Package { Err(_e) => Err(FetchError::ParseError), } } - PackageIdentifier::PackageLocator(l) => Ok(PKGFile::default()) + PackageIdentifier::PackageLocator(l) => unimplemented!() }; pkgfile