feat: info is now an info command and fixed logging

This commit is contained in:
Strix 2023-10-14 22:39:50 +02:00
parent 8d6ed71dfc
commit 19b834e65d
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
3 changed files with 45 additions and 10 deletions

View file

@ -12,6 +12,16 @@ pub enum PackageType {
Meta, 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)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)] #[serde(default)]
pub struct Package { pub struct Package {

View file

@ -4,6 +4,7 @@ use clap::{Parser, Subcommand};
use log::{debug, error, info, trace, warn}; use log::{debug, error, info, trace, warn};
use colored::Colorize; use colored::Colorize;
use manifest::package::PackageType;
use crate::CONFIG; use crate::CONFIG;
use crate::package::identifier::PackageIdentifier; use crate::package::identifier::PackageIdentifier;
use crate::package::Package; use crate::package::Package;
@ -40,10 +41,9 @@ pub enum Command {
}, },
/// Update packages on the system /// Update packages on the system
Update, Update,
/// Get info about pkgr /// Get info about a package
Info { Info {
#[arg(short, long, default_value_t = false)] package_identifier: Option<PackageIdentifier>
detailed: bool
}, },
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
Debug, Debug,
@ -114,12 +114,34 @@ impl Command {
error!("Update is not yet implemented."); error!("Update is not yet implemented.");
} }
Command::Info { Command::Info {
detailed package_identifier
} => { } => {
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\ info!("Welcome to pkgr!\n\
{}\n\ {}\n\
To get help please run \"{} -h\"", env!("CARGO_PKG_DESCRIPTION"), std::env::args().nth(0).unwrap()); To get help please run \"{} -h\"", env!("CARGO_PKG_DESCRIPTION"), std::env::args().nth(0).unwrap());
if *detailed {
info!(""); info!("");
info!("version: {}", env!("CARGO_PKG_VERSION")); info!("version: {}", env!("CARGO_PKG_VERSION"));
info!("authors: {}", env!("CARGO_PKG_AUTHORS")); info!("authors: {}", env!("CARGO_PKG_AUTHORS"));

View file

@ -1,7 +1,7 @@
use std::fmt::Display; use std::fmt::Display;
use std::path::Path; use std::path::Path;
use log::info; use log::{debug, info, trace};
use reqwest::blocking::get; use reqwest::blocking::get;
use pkgfile::PKGFile; use pkgfile::PKGFile;
@ -104,6 +104,7 @@ impl TryFetch<PackageIdentifier> for Package {
/// Fetch a package from a package identifier. /// Fetch a package from a package identifier.
fn try_fetch(query: PackageIdentifier) -> Result<Package, Self::Error> { fn try_fetch(query: PackageIdentifier) -> Result<Package, Self::Error> {
trace!("Fetching: {query:#?}");
let pkgfile = match &query { let pkgfile = match &query {
PackageIdentifier::Path(s) => match PKGFile::try_from(Path::new(&s)) { PackageIdentifier::Path(s) => match PKGFile::try_from(Path::new(&s)) {
Ok(p) => Ok(p), Ok(p) => Ok(p),
@ -111,8 +112,10 @@ impl TryFetch<PackageIdentifier> for Package {
}, },
PackageIdentifier::URI(s) => { PackageIdentifier::URI(s) => {
let mut bytes = Vec::new(); let mut bytes = Vec::new();
debug!("sending GET request...");
match get::<String>(s.into()) { match get::<String>(s.into()) {
Ok(response) => { Ok(response) => {
debug!("Got response!");
if let Ok(b) = response.bytes() { if let Ok(b) = response.bytes() {
bytes.extend(b); bytes.extend(b);
} }
@ -125,7 +128,7 @@ impl TryFetch<PackageIdentifier> for Package {
Err(_e) => Err(FetchError::ParseError), Err(_e) => Err(FetchError::ParseError),
} }
} }
PackageIdentifier::PackageLocator(l) => Ok(PKGFile::default()) PackageIdentifier::PackageLocator(l) => unimplemented!()
}; };
pkgfile pkgfile