diff options
| -rw-r--r-- | Cargo.lock | 7 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/main.rs | 19 | 
3 files changed, 19 insertions, 8 deletions
| @@ -13,6 +13,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"  checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"  [[package]] +name = "anyhow" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" + +[[package]]  name = "autocfg"  version = "1.0.1"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -337,6 +343,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"  name = "formurapid"  version = "0.0.1"  dependencies = [ + "anyhow",   "derive_builder",   "exitcode",   "getopts", @@ -4,6 +4,7 @@ version = "0.0.1"  edition = "2018"  [dependencies] +anyhow = "1.0.40"  derive_builder = "0.10.0"  exitcode = "1.1.2"  getopts = "0.2.21" diff --git a/src/main.rs b/src/main.rs index 8961809..e064bfc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use anyhow;  use derive_builder::Builder;  use getopts::Options;  use pdf_forms::{Form, FieldType}; @@ -61,7 +62,7 @@ fn main() {              toml_path,              form_path.with_file_name(output_file_name),              &mut form, -        ); +        ).unwrap();      } else if opt_matches.opt_present("generate") {          let ids_path = form_path.with_file_name(              format!("{}-ids.pdf", form_file_prefix) @@ -126,20 +127,22 @@ fn fill<P: AsRef<Path>>(      data_path: P,      output_path: P,      form: &mut Form, -) { +) -> anyhow::Result<()> {      let mut buf = Vec::new(); -    let mut file = File::open(data_path).unwrap(); -    file.read_to_end(&mut buf).unwrap(); +    let mut file = File::open(data_path)?; +    file.read_to_end(&mut buf)?; -    let data: TextForm = toml::from_slice(&buf).unwrap(); +    let data: TextForm = toml::from_slice(&buf)?;      for field in data.fields {          if let Some(value) = field.value { -            form.set_text(field.id, value.to_owned()).unwrap(); +            form.set_text(field.id, value.to_owned())?;          } else if let Some(state) = field.state { -            form.set_check_box(field.id, state).unwrap(); +            form.set_check_box(field.id, state)?;          }      } -    form.save(output_path).unwrap(); +    form.save(output_path)?; + +    Ok(())  } | 
