use clap::{Arg, ArgMatches};
use log::LevelFilter;
pub fn configs<'a>() -> Vec<Arg<'a, 'a>> {
vec![
Arg::with_name("from")
.long("from")
.takes_value(true)
.value_name("PLUGIN")
.help("Plugin used to decode the hard-copy (e.g. plugins.pgpfone)."),
Arg::with_name("output")
.short("o")
.long("output")
.takes_value(true)
.value_name("FILE")
.help("Output file path for the reconstructed data (decode mode)."),
Arg::with_name("verify")
.long("verify")
.help("Validate a reconstructed file against a checksum from the hard-copy."),
Arg::with_name("debug")
.long("debug")
.help("Enable debug mode to emit more details."),
Arg::with_name("FILE")
.index(1)
.value_name("FILE")
.help("Output file (decode mode) or file to verify (--verify mode)."),
]
}
pub struct SoftCopyConfig {
pub plugin: Option<String>,
pub output: Option<String>,
pub file: Option<String>,
pub verify: bool,
pub debug: bool,
}
impl SoftCopyConfig {
pub fn get_log_level(&self) -> LevelFilter {
if self.debug {
LevelFilter::Debug
} else {
LevelFilter::Warn
}
}
}
impl<'a> From<ArgMatches<'a>> for SoftCopyConfig {
fn from(matches: ArgMatches<'a>) -> Self {
SoftCopyConfig {
plugin: matches.value_of("from").map(str::to_string),
output: matches.value_of("output").map(str::to_string),
file: matches.value_of("FILE").map(str::to_string),
verify: matches.is_present("verify"),
debug: matches.is_present("debug"),
}
}
}