Compare commits

...

5 commits

Author SHA1 Message Date
a28d17d5da fix(cli): accept "-" for stdin marker at any position #2
Some checks failed
cargo devel CI / cargo CI (push) Failing after 1m16s
2024-05-24 09:18:51 +02:00
11f704804a chore: add log to libpt features
Some checks failed
cargo devel CI / cargo CI (push) Failing after 1m13s
2024-05-23 14:57:17 +02:00
c21b44b1bc chore: fix regression from #5, don't show time if not in meta logging mode 2024-05-23 14:56:37 +02:00
93b01f27cd docs(help): dirs cannot be dumped #4
Some checks failed
cargo devel CI / cargo CI (push) Failing after 1m14s
2024-05-23 14:55:03 +02:00
b9d0f82ccb fix: less dependencies and simpler cli #6
Some checks failed
cargo devel CI / cargo CI (push) Failing after 1m15s
2024-05-23 14:51:56 +02:00
2 changed files with 13 additions and 20 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", "log"], 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)]
@ -57,17 +55,19 @@ pub struct Cli {
/// a data source, probably a file. /// a data source, probably a file.
/// ///
/// If left empty or set as "-", the program will read from stdin. /// If left empty or set as "-", the program will read from stdin.
///
/// Directories cannot be dumped.
pub data_source: Vec<String>, pub data_source: Vec<String>,
} }
fn main() { fn main() {
let mut cli = cli_parse(); let mut cli = cli_parse();
let mut sources: Vec<Box<dyn DataSource>> = Vec::new(); let mut sources: Vec<Box<dyn DataSource>> = Vec::new();
if !cli.data_source.is_empty() && cli.data_source[0] != "-" { if !cli.data_source.is_empty() && !cli.data_source.contains(&"-".to_string()) {
for data_source in &cli.data_source { for data_source in &cli.data_source {
let data_source: PathBuf = PathBuf::from(data_source); let data_source: PathBuf = PathBuf::from(data_source);
if data_source.is_dir() { if data_source.is_dir() {
warn!("Not a file {:?}, skipping", data_source); warn!("'{:?}' is a directory and cannot be dumped, skipping", data_source);
// std::process::exit(1); // std::process::exit(1);
continue; continue;
} }
@ -119,21 +119,16 @@ 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();
} else { } else {
// less verbose version // less verbose version
let _ = Logger::builder().build(); let _ = Logger::builder().show_time(false).build();
} }
cli cli
} }