feat: some changes to logging
All checks were successful
/ check (push) Successful in 37s

This commit is contained in:
Didier Slof 2023-07-17 12:13:14 +02:00
parent 6fd8d5e45e
commit 1a95046b87
Signed by: didier
GPG key ID: 01E71F18AA4398E5
3 changed files with 30 additions and 14 deletions

View file

@ -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"

View file

@ -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,9 +49,13 @@ impl Command {
error!("Install is not yet implemented.");
}
}
Command::Remove { package_identifier: _ } => {
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.");
}

View file

@ -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()
}