generated from PlexSheep/rs-base
Compare commits
5 commits
256b362f39
...
a28d17d5da
Author | SHA1 | Date | |
---|---|---|---|
a28d17d5da | |||
11f704804a | |||
c21b44b1bc | |||
93b01f27cd | |||
b9d0f82ccb |
2 changed files with 13 additions and 20 deletions
|
@ -12,8 +12,6 @@ repository = "https://git.cscherr.de/PlexSheep/hedu"
|
|||
keywords = ["hexdumper"]
|
||||
|
||||
[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-num = { version = "1.0.2" }
|
||||
clap-verbosity-flag = { version = "2.0.1" }
|
||||
anyhow = "1.0.79"
|
||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -8,7 +8,6 @@ use std::{fs::File, io::IsTerminal, path::PathBuf};
|
|||
use libpt::log::{error, trace, warn, Level, Logger};
|
||||
|
||||
use clap::Parser;
|
||||
use clap_verbosity_flag::{InfoLevel, Verbosity};
|
||||
|
||||
mod dumper;
|
||||
use dumper::{DataSource, Hedu};
|
||||
|
@ -29,10 +28,9 @@ Author: {author-with-newline}
|
|||
)]
|
||||
/// Hexdumper written in Rust
|
||||
pub struct Cli {
|
||||
// clap_verbosity_flag seems to make this a global option implicitly
|
||||
/// set a verbosity, multiple allowed (f.e. -vvv)
|
||||
#[command(flatten)]
|
||||
pub verbose: Verbosity<InfoLevel>,
|
||||
/// show more details
|
||||
#[arg(short, long)]
|
||||
pub verbose: bool,
|
||||
|
||||
/// show additional logging meta data
|
||||
#[arg(long)]
|
||||
|
@ -57,17 +55,19 @@ pub struct Cli {
|
|||
/// a data source, probably a file.
|
||||
///
|
||||
/// If left empty or set as "-", the program will read from stdin.
|
||||
///
|
||||
/// Directories cannot be dumped.
|
||||
pub data_source: Vec<String>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut cli = cli_parse();
|
||||
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 {
|
||||
let data_source: PathBuf = PathBuf::from(data_source);
|
||||
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);
|
||||
continue;
|
||||
}
|
||||
|
@ -119,21 +119,16 @@ fn main() {
|
|||
|
||||
fn cli_parse() -> Cli {
|
||||
let cli = Cli::parse();
|
||||
let ll: Level = match cli.verbose.log_level().unwrap().as_str() {
|
||||
"TRACE" => Level::TRACE,
|
||||
"DEBUG" => Level::DEBUG,
|
||||
"INFO" => Level::INFO,
|
||||
"WARN" => Level::WARN,
|
||||
"ERROR" => Level::ERROR,
|
||||
_ => {
|
||||
unreachable!();
|
||||
}
|
||||
let ll: Level = if cli.verbose {
|
||||
Level::INFO
|
||||
} else {
|
||||
Level::DEBUG
|
||||
};
|
||||
if cli.meta {
|
||||
let _ = Logger::builder().max_level(ll).build();
|
||||
} else {
|
||||
// less verbose version
|
||||
let _ = Logger::builder().build();
|
||||
let _ = Logger::builder().show_time(false).build();
|
||||
}
|
||||
cli
|
||||
}
|
||||
|
|
Reference in a new issue