aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs18
3 files changed, 23 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ae4aeee..ec576e4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -310,6 +310,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
[[package]]
+name = "exitcode"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193"
+
+[[package]]
name = "flate2"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -332,6 +338,7 @@ name = "formurapid"
version = "0.0.1"
dependencies = [
"derive_builder",
+ "exitcode",
"getopts",
"pdf_forms",
"serde",
diff --git a/Cargo.toml b/Cargo.toml
index af7c62b..d3479a4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,6 +5,7 @@ edition = "2018"
[dependencies]
derive_builder = "0.10.0"
+exitcode = "1.1.2"
getopts = "0.2.21"
pdf_forms = "0.3.4"
serde = { version = "1.0.125", features = ["derive"] }
diff --git a/src/main.rs b/src/main.rs
index aac82d7..8961809 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,6 +7,7 @@ use std::env;
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::path::Path;
+use std::process;
#[derive(Debug, Default, Deserialize, Serialize)]
struct TextForm<'a> {
@@ -25,6 +26,13 @@ struct Field<'a> {
state: Option<bool>,
}
+fn print_usage(opts: &Options) {
+ print!(
+ "{}",
+ opts.usage("usage: formurapid [options] (--generate | --fill) PDF_FILE"),
+ );
+}
+
fn main() {
let args: Vec<String> = env::args().collect();
@@ -35,7 +43,9 @@ fn main() {
let opt_matches = opts.parse(&args[1..]).unwrap();
if opt_matches.free.is_empty() {
- return;
+ print_usage(&opts);
+
+ process::exit(exitcode::USAGE);
}
let form_path = Path::new(&opt_matches.free[0]);
@@ -52,8 +62,6 @@ fn main() {
form_path.with_file_name(output_file_name),
&mut form,
);
-
- return;
} else if opt_matches.opt_present("generate") {
let ids_path = form_path.with_file_name(
format!("{}-ids.pdf", form_file_prefix)
@@ -64,6 +72,10 @@ fn main() {
ids_path,
&mut form,
);
+ } else {
+ print_usage(&opts);
+
+ process::exit(exitcode::USAGE);
}
}