From 1a95046b876c9346f03205ce3cf1c0ddfd45dcc1 Mon Sep 17 00:00:00 2001 From: Didier Date: Mon, 17 Jul 2023 12:13:14 +0200 Subject: [PATCH] feat: some changes to logging --- pkgr/Cargo.toml | 1 + pkgr/src/commands/mod.rs | 13 ++++++++++--- pkgr/src/main.rs | 30 +++++++++++++++++++----------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/pkgr/Cargo.toml b/pkgr/Cargo.toml index 9f719ea..6e94865 100644 --- a/pkgr/Cargo.toml +++ b/pkgr/Cargo.toml @@ -11,3 +11,4 @@ log = "0.4.19" regex = "1.9.1" manifest = { path = "../manifest" } clap = { version = "4.3.12", features = ["derive"] } +colored = "2.0.4" diff --git a/pkgr/src/commands/mod.rs b/pkgr/src/commands/mod.rs index 3c52aca..8697d80 100644 --- a/pkgr/src/commands/mod.rs +++ b/pkgr/src/commands/mod.rs @@ -3,7 +3,7 @@ use clap::{Parser, Subcommand}; use log::error; #[derive(Parser, Debug)] -#[clap(name = "pkgr", version = "0.1.0", author = "")] +#[clap(name = "pkgr", version)] pub struct Cli { #[command(subcommand)] pub command: Command, @@ -19,6 +19,9 @@ pub enum Command { }, /// Remove a package from the system Remove { + /// Remove the package from index too + #[arg(short, long, default_value_t = false)] + index: bool, package_identifier: PackageIdentifier, }, /// List packages @@ -46,8 +49,12 @@ impl Command { error!("Install is not yet implemented."); } } - Command::Remove { package_identifier: _ } => { - error!("Remove is not yet implemented."); + Command::Remove { package_identifier: _, index } => { + if *index { + error!("Index removal is not yet implemented."); + } else { + error!("Remove is not yet implemented."); + } } Command::List { installed: _ } => { error!("List is not yet implemented."); diff --git a/pkgr/src/main.rs b/pkgr/src/main.rs index 17e200f..e8c878a 100644 --- a/pkgr/src/main.rs +++ b/pkgr/src/main.rs @@ -1,10 +1,8 @@ use clap::Parser; - - - - -use crate::commands::{Cli}; -use log::{info, SetLoggerError}; +use colored::Colorize; +use crate::commands::Cli; +use log::{debug, info, SetLoggerError, trace}; +use std::env; mod commands; mod package; @@ -12,8 +10,16 @@ mod package; fn main() { setup_logger().expect("Unable to setup logger."); + trace!("Parsing command line arguments..."); let c = Cli::parse(); - info!("Command: {:?}", c); + debug!("Command line arguments parsed."); + + trace!("Executing command..."); + c.command.execute(); + debug!("Command executed."); + + trace!("Exiting..."); + info!("Done."); } fn setup_logger() -> Result<(), SetLoggerError> { @@ -22,13 +28,15 @@ fn setup_logger() -> Result<(), SetLoggerError> { out.finish(format_args!( "{} {}", match record.level().to_string().chars().nth(0).unwrap_or('I') { - 'E' | 'W' => "!!", - _ => "**", + 'T' => "##".cyan(), + 'D' => "::".yellow(), + 'E' | 'W' => "!!".red(), + _ => "**".blue(), }, - message + message.to_string().bright_white() )) }) - .level(log::LevelFilter::Info) + .level(env::var("PKGR_LOG_LEVEL").unwrap_or_else(|_| "info".to_string()).parse().unwrap_or(log::LevelFilter::Info)) .chain(std::io::stdout()) .apply() }