fix!: less dependencies and simpler cli #6

This commit is contained in:
Christoph J. Scherr 2024-05-23 14:51:56 +02:00
parent f6c9c3c820
commit fb145a7ff4
2 changed files with 8 additions and 17 deletions

View File

@ -12,8 +12,6 @@ repository = "https://git.cscherr.de/PlexSheep/hedu"
keywords = ["hexdumper"] keywords = ["hexdumper"]
[dependencies] [dependencies]
libpt = { version = "0.5.1", features = ["log", "bintols"] } libpt = { version = "0.5.1", features = ["bintols"], default-features = false }
clap = { version = "4.4.4", features = ["derive", "help"] } clap = { version = "4.4.4", features = ["derive", "help"] }
clap-num = { version = "1.0.2" }
clap-verbosity-flag = { version = "2.0.1" }
anyhow = "1.0.79" anyhow = "1.0.79"

View File

@ -8,7 +8,6 @@ use std::{fs::File, io::IsTerminal, path::PathBuf};
use libpt::log::{error, trace, warn, Level, Logger}; use libpt::log::{error, trace, warn, Level, Logger};
use clap::Parser; use clap::Parser;
use clap_verbosity_flag::{InfoLevel, Verbosity};
mod dumper; mod dumper;
use dumper::{DataSource, Hedu}; use dumper::{DataSource, Hedu};
@ -29,10 +28,9 @@ Author: {author-with-newline}
)] )]
/// Hexdumper written in Rust /// Hexdumper written in Rust
pub struct Cli { pub struct Cli {
// clap_verbosity_flag seems to make this a global option implicitly /// show more details
/// set a verbosity, multiple allowed (f.e. -vvv) #[arg(short, long)]
#[command(flatten)] pub verbose: bool,
pub verbose: Verbosity<InfoLevel>,
/// show additional logging meta data /// show additional logging meta data
#[arg(long)] #[arg(long)]
@ -119,15 +117,10 @@ fn main() {
fn cli_parse() -> Cli { fn cli_parse() -> Cli {
let cli = Cli::parse(); let cli = Cli::parse();
let ll: Level = match cli.verbose.log_level().unwrap().as_str() { let ll: Level = if cli.verbose {
"TRACE" => Level::TRACE, Level::INFO
"DEBUG" => Level::DEBUG, } else {
"INFO" => Level::INFO, Level::DEBUG
"WARN" => Level::WARN,
"ERROR" => Level::ERROR,
_ => {
unreachable!();
}
}; };
if cli.meta { if cli.meta {
let _ = Logger::builder().max_level(ll).build(); let _ = Logger::builder().max_level(ll).build();