Skip to content

Instantly share code, notes, and snippets.

@mysteriouspants
Created October 5, 2018 07:01
Show Gist options
  • Save mysteriouspants/f3f375adc3012d0504a963b70c62fdb5 to your computer and use it in GitHub Desktop.
Save mysteriouspants/f3f375adc3012d0504a963b70c62fdb5 to your computer and use it in GitHub Desktop.
extern crate clap;
extern crate reqwest;
use std::thread;
use clap::{Arg, App};
fn main() {
let args = App::new("webget")
.version("1.0")
.author("Desert Code Camp 2018")
.about("Runs get on a url and prints the response")
.arg(Arg::with_name("URL")
.required(true)
.index(1)
.multiple(true))
.get_matches();
let mut handles = vec![];
for u in args.values_of("URL").unwrap() {
let url = u.clone();
let handle = thread::spawn(move || {
reqwest::get(url)
});
handles.push(handle);
}
for handle in handles {
let mut result = handle.join().unwrap();
match result {
Ok(mut r) => {
println!("response = {:?}", r);
println!("body = {:?}", r.text());
},
Err(e) => {
println!("Failed to get {:?}", e);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment