Improved docs + a bunch of fixes
+ Better error handling + Line numbers in toml errors should now match the file + Errors during parsing show where in the bit stream they failed + Fixed some issues with string, float, and double parsing reporting the wrong bit width + Updated docs and added the example.toml config + clipppy + fmt
This commit is contained in:
8 files changed
+309
-169
No files matched your search
+14
-11
@@ -1,4 +1,5 @@
|
||||
use crate::error::FormatyError;
|
||||
use crate::formatter::format::Format;
|
||||
use crate::parser::parse_bytes_from_input_arg;
|
||||
use formatter::FormatConfig;
|
||||
use std::path::PathBuf;
|
||||
@@ -27,7 +28,7 @@ pub struct Args {
|
||||
data: Vec<String>,
|
||||
}
|
||||
|
||||
fn formaty() -> Result<(), FormatyError> {
|
||||
fn init() -> Result<(Vec<u8>, Format), FormatyError> {
|
||||
let args: Args = Args::from_args();
|
||||
|
||||
let config = FormatConfig::new(&args.config)?;
|
||||
@@ -36,22 +37,24 @@ fn formaty() -> Result<(), FormatyError> {
|
||||
.formats
|
||||
.iter()
|
||||
.find(|f| f.name == args.format)
|
||||
.ok_or_else(|| FormatyError::FormatNotFound(args.format.to_string()))?;
|
||||
.ok_or_else(|| FormatyError::FormatNotFound(args.format.to_string()))?
|
||||
.clone();
|
||||
|
||||
let data = parse_bytes_from_input_arg(args.data).unwrap();
|
||||
|
||||
let data = format.format_data(&data)?;
|
||||
|
||||
println!("{}", data);
|
||||
|
||||
Ok(())
|
||||
Ok((data, format))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match formaty() {
|
||||
Ok(_) => {}
|
||||
let (data, format) = match init() {
|
||||
Ok((data, format)) => (data, format),
|
||||
Err(e) => {
|
||||
println!("Error formatting data: {}", e.to_string())
|
||||
println!("Error initializing: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
match format.format_data(&data) {
|
||||
Ok(data) => println!("{}", data),
|
||||
Err(_) => print!("Unable to parse data"),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user