aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-03-27 09:02:59 -0600
committerMelody Horn <melody@boringcactus.com>2021-03-27 09:02:59 -0600
commit4e79ab051917fece21fcec0bd31cc2942462fda0 (patch)
treef2fad4c246cf8f4c7c4f7bc8b3f0e38a5b421079 /src/main.rs
downloadwebget-4e79ab051917fece21fcec0bd31cc2942462fda0.tar.gz
webget-4e79ab051917fece21fcec0bd31cc2942462fda0.zip
rough draft
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..da1ae1f
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,39 @@
+use std::mem;
+use std::path::PathBuf;
+
+use anyhow::Error;
+use hyper::Uri;
+use structopt::StructOpt;
+
+mod download;
+use download::download;
+
+#[derive(StructOpt, Debug)]
+struct Args {
+ /// Specify output filename (will cause an error if multiple URLs are given)
+ #[structopt(short = "O", long)]
+ output_document: Option<PathBuf>,
+
+ /// The URLs to download
+ urls: Vec<Uri>,
+}
+
+#[tokio::main]
+async fn main() -> Result<(), Error> {
+ let (args, urls) = {
+ let mut args: Args = Args::from_args();
+ let urls = mem::take(&mut args.urls);
+ (args, urls)
+ };
+ if urls.len() != 1 && args.output_document.is_some() {
+ panic!("can't use the same output file for multiple URLs!")
+ }
+
+ let download_handles = urls
+ .into_iter()
+ .map(|url| download(url, &args));
+ let downloads = futures::future::join_all(download_handles);
+ let _downloads = downloads.await;
+
+ Ok(())
+}