38 lines
849 B
Rust
38 lines
849 B
Rust
|
use crate::parser::parse_bytes_from_input_arg;
|
||
|
use formatter::FormatConfig;
|
||
|
use std::path::PathBuf;
|
||
|
use structopt::StructOpt;
|
||
|
|
||
|
mod byte_stream;
|
||
|
mod formatter;
|
||
|
mod parser;
|
||
|
|
||
|
#[derive(Debug, StructOpt)]
|
||
|
#[structopt(name = "Formaty", about = "Arbitrary Binary Data Formatting")]
|
||
|
pub struct Args {
|
||
|
#[structopt(parse(from_os_str))]
|
||
|
config: PathBuf,
|
||
|
|
||
|
format: String,
|
||
|
|
||
|
data: Vec<String>,
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let args: Args = Args::from_args();
|
||
|
|
||
|
let config = FormatConfig::new(&args.config).unwrap();
|
||
|
|
||
|
let format = match config.formats.iter().find(|f| f.name == args.format) {
|
||
|
None => {
|
||
|
println!("Format not found in config file");
|
||
|
return;
|
||
|
}
|
||
|
Some(format) => format,
|
||
|
};
|
||
|
|
||
|
let data = parse_bytes_from_input_arg(args.data).unwrap();
|
||
|
|
||
|
println!("{}", format.format_data(&data));
|
||
|
}
|