aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index da1ae1f..21b4d82 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,5 @@
+use std::fs;
+use std::io::{self, BufRead};
use std::mem;
use std::path::PathBuf;
@@ -10,6 +12,10 @@ use download::download;
#[derive(StructOpt, Debug)]
struct Args {
+ /// Read URLs from a file
+ #[structopt(short, long)]
+ input_file: Option<PathBuf>,
+
/// Specify output filename (will cause an error if multiple URLs are given)
#[structopt(short = "O", long)]
output_document: Option<PathBuf>,
@@ -22,7 +28,16 @@ struct Args {
async fn main() -> Result<(), Error> {
let (args, urls) = {
let mut args: Args = Args::from_args();
- let urls = mem::take(&mut args.urls);
+ let mut urls = mem::take(&mut args.urls);
+ if let Some(input_file) = &args.input_file {
+ if let Ok(input_file) = fs::File::open(input_file) {
+ let input_file = io::BufReader::new(input_file);
+ let input_file_urls = input_file
+ .lines()
+ .filter_map(|line| line.ok().and_then(|line| line.parse().ok()));
+ urls.extend(input_file_urls);
+ }
+ }
(args, urls)
};
if urls.len() != 1 && args.output_document.is_some() {