feat: some changes to logging
This commit is contained in:
parent
b34cdb4aa4
commit
3a21d12c07
3 changed files with 30 additions and 14 deletions
|
@ -11,3 +11,4 @@ log = "0.4.19"
|
||||||
regex = "1.9.1"
|
regex = "1.9.1"
|
||||||
manifest = { path = "../manifest" }
|
manifest = { path = "../manifest" }
|
||||||
clap = { version = "4.3.12", features = ["derive"] }
|
clap = { version = "4.3.12", features = ["derive"] }
|
||||||
|
colored = "2.0.4"
|
||||||
|
|
|
@ -3,7 +3,7 @@ use clap::{Parser, Subcommand};
|
||||||
use log::error;
|
use log::error;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(name = "pkgr", version = "0.1.0", author = "")]
|
#[clap(name = "pkgr", version)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
pub command: Command,
|
pub command: Command,
|
||||||
|
@ -19,6 +19,9 @@ pub enum Command {
|
||||||
},
|
},
|
||||||
/// Remove a package from the system
|
/// Remove a package from the system
|
||||||
Remove {
|
Remove {
|
||||||
|
/// Remove the package from index too
|
||||||
|
#[arg(short, long, default_value_t = false)]
|
||||||
|
index: bool,
|
||||||
package_identifier: PackageIdentifier,
|
package_identifier: PackageIdentifier,
|
||||||
},
|
},
|
||||||
/// List packages
|
/// List packages
|
||||||
|
@ -46,9 +49,13 @@ impl Command {
|
||||||
error!("Install is not yet implemented.");
|
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.");
|
error!("Remove is not yet implemented.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Command::List { installed: _ } => {
|
Command::List { installed: _ } => {
|
||||||
error!("List is not yet implemented.");
|
error!("List is not yet implemented.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use colored::Colorize;
|
||||||
|
use crate::commands::Cli;
|
||||||
|
use log::{debug, info, SetLoggerError, trace};
|
||||||
|
use std::env;
|
||||||
use crate::commands::{Cli};
|
|
||||||
use log::{info, SetLoggerError};
|
|
||||||
|
|
||||||
mod commands;
|
mod commands;
|
||||||
mod package;
|
mod package;
|
||||||
|
@ -12,8 +10,16 @@ mod package;
|
||||||
fn main() {
|
fn main() {
|
||||||
setup_logger().expect("Unable to setup logger.");
|
setup_logger().expect("Unable to setup logger.");
|
||||||
|
|
||||||
|
trace!("Parsing command line arguments...");
|
||||||
let c = Cli::parse();
|
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> {
|
fn setup_logger() -> Result<(), SetLoggerError> {
|
||||||
|
@ -22,13 +28,15 @@ fn setup_logger() -> Result<(), SetLoggerError> {
|
||||||
out.finish(format_args!(
|
out.finish(format_args!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
match record.level().to_string().chars().nth(0).unwrap_or('I') {
|
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())
|
.chain(std::io::stdout())
|
||||||
.apply()
|
.apply()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue