Added deframer support
This commit is contained in:
13 files changed
+529
-322
No files matched your search
+18
-10
@@ -1,11 +1,12 @@
|
||||
use crate::error::FormatyError;
|
||||
use crate::formatter::format::Format;
|
||||
use crate::parser::InputTypes;
|
||||
use formatter::FormatConfig;
|
||||
use formatter::format_config::FormatConfig;
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
mod byte_stream;
|
||||
mod deframer;
|
||||
mod error;
|
||||
mod formatter;
|
||||
mod parser;
|
||||
@@ -48,6 +49,13 @@ pub struct Args {
|
||||
#[structopt(help = "Input data from stdin", short = "s", long = "stdin")]
|
||||
input_stdin: bool,
|
||||
|
||||
#[structopt(
|
||||
help = "Additional deframers to apply to the data before trying to parse it",
|
||||
short = "d",
|
||||
long = "deframer"
|
||||
)]
|
||||
deframer: Option<Vec<String>>,
|
||||
|
||||
#[structopt(help = "Format to parse data as")]
|
||||
format: String,
|
||||
|
||||
@@ -55,26 +63,26 @@ pub struct Args {
|
||||
data: Vec<String>,
|
||||
}
|
||||
|
||||
fn init() -> Result<(Vec<u8>, Format, FormatConfig), FormatyError> {
|
||||
let args: Args = Args::from_args();
|
||||
|
||||
fn init(args: &Args) -> Result<(Vec<u8>, Format, FormatConfig), FormatyError> {
|
||||
let config = FormatConfig::new(&args.config, &args.global_config)?;
|
||||
|
||||
let format = config.get_format(&args.format)?;
|
||||
|
||||
let data = if args.input_stdin {
|
||||
args.input_type.parse_stdin(args.base)?
|
||||
} else if let Some(input_file) = args.input_file {
|
||||
args.input_type.parse_file(&input_file, args.base)?
|
||||
} else if let Some(input_file) = &args.input_file {
|
||||
args.input_type.parse_file(input_file, args.base)?
|
||||
} else {
|
||||
args.input_type.parse_arg_input(args.data, args.base)?
|
||||
args.input_type
|
||||
.parse_arg_input(args.data.clone(), args.base)?
|
||||
};
|
||||
|
||||
Ok((data, format, config))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let (data, format, config) = match init() {
|
||||
let args: Args = Args::from_args();
|
||||
let (data, format, config) = match init(&args) {
|
||||
Ok((data, format, config)) => (data, format, config),
|
||||
Err(e) => {
|
||||
println!("Error initializing: {}", e);
|
||||
@@ -82,8 +90,8 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
match format.format_data(&data, &config) {
|
||||
match format.format_data(&data, &config, args.deframer) {
|
||||
Ok(data) => println!("{}", data),
|
||||
Err(_) => print!("Unable to parse data"),
|
||||
Err(err) => print!("Unable to parse data: {}", err),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user