diff options
| -rw-r--r-- | doc/formurapid.1 | 6 | ||||
| -rw-r--r-- | doc/formurapid.1.txt | 2 | ||||
| -rw-r--r-- | src/main.rs | 72 | 
3 files changed, 42 insertions, 38 deletions
| diff --git a/doc/formurapid.1 b/doc/formurapid.1 index 21d160f..f42c2a4 100644 --- a/doc/formurapid.1 +++ b/doc/formurapid.1 @@ -2,12 +2,12 @@  .\"     Title: formurapid  .\"    Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]  .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/> -.\"      Date: 04/17/2021 +.\"      Date: 04/18/2021  .\"    Manual: \ \&  .\"    Source: \ \&  .\"  Language: English  .\" -.TH "FORMURAPID" "1" "04/17/2021" "\ \&" "\ \&" +.TH "FORMURAPID" "1" "04/18/2021" "\ \&" "\ \&"  .\" -----------------------------------------------------------------  .\" * Define some portability stuff  .\" ----------------------------------------------------------------- @@ -31,7 +31,7 @@  formurapid \- Fill in a PDF form using a text file  .SH "SYNOPSIS"  .sp -\fIformurapid\fR [options] (\-\-generate | \-\-fill) \fIpdf_file\fR +\fIformurapid\fR [options] (\-\-generate | \-\-fill) \fIpdf_file\fR \fI\&...\fR  .SH "DESCRIPTION"  .sp  Fill in a PDF form based on the values in a TOML text file\&. This allows the values to be saved and reused\&. The TOML file can also be manipulated by external programs to calculate or fill in values in an interoperable format without having to directly manipulate the PDF\&. diff --git a/doc/formurapid.1.txt b/doc/formurapid.1.txt index 596d7aa..d9edf69 100644 --- a/doc/formurapid.1.txt +++ b/doc/formurapid.1.txt @@ -7,7 +7,7 @@ formurapid - Fill in a PDF form using a text file  SYNOPSIS  -------- -'formurapid' [options] (--generate | --fill) 'pdf_file' +'formurapid' [options] (--generate | --fill) 'pdf_file' '...'  DESCRIPTION  ----------- diff --git a/src/main.rs b/src/main.rs index 4c4d91c..18eb95c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,7 +46,7 @@ struct Field<'a> {  fn print_usage(opts: &Options) {      print!(          "{}", -        opts.usage("usage: formurapid [options] (--generate | --fill) PDF_FILE"), +        opts.usage("usage: formurapid [options] (--generate | --fill) PDF_FILE..."),      );  } @@ -89,40 +89,44 @@ fn run() -> anyhow::Result<()> {          process::exit(exitcode::USAGE);      } -    let form_path = Path::new(&opt_matches.free[0]); -    let form_file_prefix = form_path -        .file_stem() -        .ok_or(anyhow::anyhow!("no file name"))? -        .to_str() -        .ok_or(anyhow::anyhow!("error converting file name"))?; - -    let toml_file_name = format!("{}.toml", form_file_prefix); -    let toml_path = form_path.with_file_name(toml_file_name); -    let output_file_name = format!("{}-filled.pdf", form_file_prefix); - -    let mut form = Form::load(form_path)?; - -    if opt_matches.opt_present("fill") { -        return fill( -            toml_path, -            form_path.with_file_name(output_file_name), -            &mut form, -        ); -    } else if opt_matches.opt_present("generate") { -        let ids_path = form_path.with_file_name( -            format!("{}-ids.pdf", form_file_prefix) -        ); - -        return generate_fill_helpers( -            toml_path, -            ids_path, -            &mut form, -        ); -    } else { -        print_usage(&opts); - -        process::exit(exitcode::USAGE); +    for pdf_path in &opt_matches.free { +        let form_path = Path::new(&pdf_path); +        let form_file_prefix = form_path +            .file_stem() +            .ok_or(anyhow::anyhow!("no file name"))? +            .to_str() +            .ok_or(anyhow::anyhow!("error converting file name"))?; + +        let toml_file_name = format!("{}.toml", form_file_prefix); +        let toml_path = form_path.with_file_name(toml_file_name); +        let output_file_name = format!("{}-filled.pdf", form_file_prefix); + +        let mut form = Form::load(form_path)?; + +        if opt_matches.opt_present("fill") { +            fill( +                toml_path, +                form_path.with_file_name(output_file_name), +                &mut form, +            )?; +        } 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, +            )?; +        } else { +            print_usage(&opts); + +            process::exit(exitcode::USAGE); +        }      } + +    Ok(())  }  /// Generate files to fill in the form. | 
