Added file input + stdin support

+ Files/stdin input can be binary or ascii
+ Handles piping from other programs
+ Misc test fixes
+ Updated readme
+ clippy + fmt
This commit is contained in:
joeyahines committed 2022-05-07 18:35:06 -06:00
1 parent 287ba32ea7
commit f2cec4c89e
6 files changed
+146 -17

No files matched your search

+14 -1
View File
@@ -42,6 +42,12 @@ pub struct Args {
#[structopt(help = "Base of the input values", short = "b", long = "base")]
base: Option<u32>,
#[structopt(help = "Input data from file", short = "f", long = "file")]
input_file: Option<PathBuf>,
#[structopt(help = "Input data from stdin", short = "s", long = "stdin")]
input_stdin: bool,
#[structopt(help = "Format to parse data as")]
format: String,
@@ -56,7 +62,14 @@ fn init() -> Result<(Vec<u8>, Format), FormatyError> {
let format = config.get_format(&args.format)?;
let data = args.input_type.parse_input(args.data, args.base)?;
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 {
args.input_type.parse_arg_input(args.data, args.base)?
};
Ok((data, format))
}