feat: some changes to logging

This commit is contained in:
Strix 2023-10-14 22:39:43 +02:00
parent b34cdb4aa4
commit 3a21d12c07
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
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()
}