aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2019-11-02 04:28:56 +0100
committerTeddy Wing2019-11-02 04:28:56 +0100
commit523170630fd8e9ba695f4167d132a8812d814a1e (patch)
tree66bfa48a052989142c9ce825cacab5c3ce30f5bd
parentad6c69f73e23896a496090b6046ea0bb40e45f45 (diff)
downloadpdf-urls-523170630fd8e9ba695f4167d132a8812d814a1e.tar.bz2
main: Accept a file path as a command line argument
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs19
3 files changed, 26 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5039940..a653ec4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -147,6 +147,11 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "exitcode"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "flate2"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -278,6 +283,7 @@ dependencies = [
name = "pdf-urls"
version = "0.0.1"
dependencies = [
+ "exitcode 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lopdf 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -388,6 +394,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a"
"checksum encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18"
"checksum encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
+"checksum exitcode 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193"
"checksum flate2 1.0.12 (registry+https://github.com/rust-lang/crates.io-index)" = "ad3c5233c9a940c8719031b423d7e6c16af66e031cb0420b0896f5245bf181d3"
"checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
diff --git a/Cargo.toml b/Cargo.toml
index 9f7eefe..ce469a5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,4 +4,5 @@ version = "0.0.1"
edition = "2018"
[dependencies]
+exitcode = "1.1.2"
lopdf = "0.23.0"
diff --git a/src/main.rs b/src/main.rs
index 049fcd2..3f77e96 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,7 +1,24 @@
+extern crate exitcode;
+
+use std::env;
+use std::process;
+
use pdf_urls::get_urls_from_pdf;
+fn print_usage() {
+ println!("usage: pdf-urls FILE");
+}
+
fn main() {
- match get_urls_from_pdf("example.pdf") {
+ let args: Vec<String> = env::args().collect();
+
+ if args.len() != 2 {
+ print_usage();
+
+ process::exit(exitcode::USAGE);
+ }
+
+ match get_urls_from_pdf(&args[1]) {
Ok(urls) => {
for url in urls {
println!("{}", url);