diff --git a/src/bin/pol_export/cli.rs b/src/bin/pol_export/cli.rs new file mode 100644 index 0000000..f5ec6a7 --- /dev/null +++ b/src/bin/pol_export/cli.rs @@ -0,0 +1,22 @@ +use clap::Parser; +use dfir_toolkit::common::HasVerboseFlag; +use log::LevelFilter; + + +#[derive(Parser, Debug)] +#[clap(name=env!("CARGO_BIN_NAME"), author, version, about, long_about = None)] +pub (crate) struct Cli { + /// Name of the file to read + #[clap()] + pub (crate) polfile: String, + + #[clap(flatten)] + pub (crate) verbose: clap_verbosity_flag::Verbosity, + +} + +impl HasVerboseFlag for Cli { + fn log_level_filter(&self) -> LevelFilter { + self.verbose.log_level_filter() + } +} \ No newline at end of file diff --git a/src/bin/pol_export/main.rs b/src/bin/pol_export/main.rs index d4e328d..01b7482 100644 --- a/src/bin/pol_export/main.rs +++ b/src/bin/pol_export/main.rs @@ -1,45 +1,21 @@ use std::{ fs::File, - io::{Read, stdout}, + io::{stdout, Read}, }; use anyhow::{anyhow, Result}; use binread::{BinReaderExt, BinResult}; -use clap::Parser; +use cli::Cli; +use dfir_toolkit::common::FancyParser; +mod cli; mod policy_file_entry; use csv::Writer; use policy_file_entry::*; -use simplelog::{TermLogger, Config}; - - -#[derive(Parser, Debug)] -#[clap(name=env!("CARGO_BIN_NAME"), author, version, about, long_about = None)] -struct Args { - /// Name of the file to read - #[clap()] - polfile: String, - - #[clap(flatten)] - pub (crate) verbose: clap_verbosity_flag::Verbosity, - - /// print help in markdown format - #[arg(long, hide = true, exclusive=true)] - pub markdown_help: bool, -} fn main() -> Result<()> { - if std::env::args().any(|a| &a == "--markdown-help") { - clap_markdown::print_help_markdown::(); - return Ok(()); - } - let args = Args::parse(); - let _ = TermLogger::init( - args.verbose.log_level_filter(), - Config::default(), - simplelog::TerminalMode::Stderr, - simplelog::ColorChoice::Auto); + let args = Cli::parse_cli(); let mut polfile = File::open(args.polfile)?; @@ -56,13 +32,13 @@ fn main() -> Result<()> { } let mut wtr = Writer::from_writer(stdout()); - + loop { let entry_result: BinResult = polfile.read_le(); match entry_result { Ok(entry) => { wtr.serialize(entry)?; - }, + } Err(why) => match why { binread::Error::Io(why) if why.kind() == std::io::ErrorKind::OutOfMemory => break, binread::Error::Io(why) if why.kind() == std::io::ErrorKind::BrokenPipe => break, @@ -72,7 +48,7 @@ fn main() -> Result<()> { //continue; break; } - } + }, } } Ok(())