diff options
| author | Teddy Wing | 2021-04-11 19:00:36 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2021-04-11 19:00:36 +0200 | 
| commit | 60b04094f47b54b875bd53f5a1fecac6b5e740df (patch) | |
| tree | fc577de9b6bcef6d2edeedfa8bcee0fe62a5a573 | |
| parent | ec3bec5c679a48cf28badcb515db2f346a88c6c4 (diff) | |
| download | formurapid-60b04094f47b54b875bd53f5a1fecac6b5e740df.tar.bz2 | |
main(): Move helper file generation to a separate function
| -rw-r--r-- | src/main.rs | 25 | 
1 files changed, 19 insertions, 6 deletions
| diff --git a/src/main.rs b/src/main.rs index 455c795..aac82d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,7 @@ fn main() {      let mut opts = Options::new();      opts.optflag("", "fill", "fill in the form using a markup file"); +    opts.optflag("", "generate", "generate helper files to fill in the form");      let opt_matches = opts.parse(&args[1..]).unwrap(); @@ -53,8 +54,24 @@ fn main() {          );          return; +    } else if opt_matches.opt_present("generate") { +        let ids_path = form_path.with_file_name( +            format!("{}-ids.pdf", form_file_prefix) +        ); + +        generate_fill_helpers( +            toml_path, +            ids_path, +            &mut form, +        );      } +} +fn generate_fill_helpers<P: AsRef<Path>>( +    data_path: P, +    output_path: P, +    form: &mut Form, +) {      let mut data = TextForm::default();      for i in 0..form.len() { @@ -86,15 +103,11 @@ fn main() {      let mut toml_file = OpenOptions::new()          .create_new(true)          .write(true) -        .open(toml_path) +        .open(data_path)          .unwrap();      toml_file.write_all(&toml::to_vec(&data).unwrap()).unwrap(); -    form.save( -        form_path.with_file_name( -            format!("{}-ids.pdf", form_file_prefix) -        ), -    ).unwrap(); +    form.save(output_path).unwrap();  }  fn fill<P: AsRef<Path>>( | 
