feat: info is now an info command and fixed logging
This commit is contained in:
parent
672314ab6d
commit
f13644f11c
3 changed files with 45 additions and 10 deletions
|
@ -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 {
|
||||
|
|
|
@ -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<PackageIdentifier>
|
||||
},
|
||||
#[cfg(debug_assertions)]
|
||||
Debug,
|
||||
|
@ -114,12 +114,34 @@ impl Command {
|
|||
error!("Update is not yet implemented.");
|
||||
}
|
||||
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\
|
||||
{}\n\
|
||||
To get help please run \"{} -h\"", env!("CARGO_PKG_DESCRIPTION"), std::env::args().nth(0).unwrap());
|
||||
if *detailed {
|
||||
info!("");
|
||||
info!("version: {}", env!("CARGO_PKG_VERSION"));
|
||||
info!("authors: {}", env!("CARGO_PKG_AUTHORS"));
|
||||
|
|
|
@ -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<PackageIdentifier> for Package {
|
|||
|
||||
/// Fetch a package from a package identifier.
|
||||
fn try_fetch(query: PackageIdentifier) -> Result<Package, Self::Error> {
|
||||
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<PackageIdentifier> for Package {
|
|||
},
|
||||
PackageIdentifier::URI(s) => {
|
||||
let mut bytes = Vec::new();
|
||||
debug!("sending GET request...");
|
||||
match get::<String>(s.into()) {
|
||||
Ok(response) => {
|
||||
debug!("Got response!");
|
||||
if let Ok(b) = response.bytes() {
|
||||
bytes.extend(b);
|
||||
}
|
||||
|
@ -125,7 +128,7 @@ impl TryFetch<PackageIdentifier> for Package {
|
|||
Err(_e) => Err(FetchError::ParseError),
|
||||
}
|
||||
}
|
||||
PackageIdentifier::PackageLocator(l) => Ok(PKGFile::default())
|
||||
PackageIdentifier::PackageLocator(l) => unimplemented!()
|
||||
};
|
||||
|
||||
pkgfile
|
||||
|
|
Loading…
Reference in a new issue