add help switch
This commit is contained in:
parent
ad7ab65366
commit
63acd248ec
1 changed files with 20 additions and 3 deletions
23
src/main.rs
23
src/main.rs
|
@ -20,7 +20,7 @@ async fn main() {
|
|||
write_all().await;
|
||||
}
|
||||
"--help" => {
|
||||
panic!("not implemented");
|
||||
print_help();
|
||||
}
|
||||
_ => {
|
||||
panic!("bad command {}", cmd);
|
||||
|
@ -53,6 +53,20 @@ async fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_help() {
|
||||
println!(
|
||||
r"
|
||||
Usage: sfwikiscraper <options>
|
||||
|
||||
--help: display this help
|
||||
--all: fetch all recipes
|
||||
--tier <tier>: fetches all recipes of the nth tier
|
||||
--item <url>: fetches the recipe (only by url for now)
|
||||
--test <url>: parse the json format shipped in <url>
|
||||
"
|
||||
);
|
||||
}
|
||||
|
||||
async fn fetch_data(url: String) -> Vec<Value> {
|
||||
let webdata = reqwest::get(url)
|
||||
.await
|
||||
|
@ -150,11 +164,14 @@ async fn write_all() {
|
|||
&join_all(
|
||||
(0..9)
|
||||
.into_iter()
|
||||
.map(|i| async move { fetch_tier(i.to_string()).await })
|
||||
.map(|i| async move { fetch_tier(i.to_string()).await }),
|
||||
)
|
||||
.await
|
||||
.into_iter()
|
||||
.reduce(|mut acc, e| { acc.extend(e.iter().cloned()); acc })
|
||||
.reduce(|mut acc, e| {
|
||||
acc.extend(e.iter().cloned());
|
||||
acc
|
||||
}),
|
||||
)
|
||||
.unwrap()
|
||||
.as_bytes(),
|
||||
|
|
Loading…
Add table
Reference in a new issue