diff options
author | Sam Tay <sam.chong.tay@gmail.com> | 2020-06-04 02:26:30 -0700 |
---|---|---|
committer | Sam Tay <sam.chong.tay@gmail.com> | 2020-06-04 02:26:30 -0700 |
commit | e4946de268a7b963a234ef43b374d27e0eb3700f (patch) | |
tree | d31df917dee39becc8c0642ad5f85ce58aeb7de2 /src/main.rs | |
parent | 224547551bd7b525fd9f8c0d137c593a143d0008 (diff) |
Stash reqwest progress
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 61 |
1 files changed, 52 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs index 45788c4..5a55bfa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,59 @@ -use clap::clap_app; -use clap::App; +use clap::{App, AppSettings, Arg}; + +mod config; +mod stackexchange; + +// TODO maybe consts for these keywords? // TODO pull defaults from config file +// TODO --set-api-key KEY +// TODO --update-cache +// TODO --install-filter-key --force +//?TODO --set-default-opt opt val # e.g. --set-default-opt sites site1;site2;site3 // may require dropping the macros fn mk_app<'a, 'b>() -> App<'a, 'b> { - clap_app!(so => - (version: clap::crate_version!()) - (author: clap::crate_authors!()) - (about: clap::crate_description!()) - (@arg site: -s --site +takes_value default_value("stackoverflow") "StackExchange site") - (@arg query: ... +required "Query to search") - ) + App::new("so") + .setting(AppSettings::ColoredHelp) + .version(clap::crate_version!()) + .author(clap::crate_authors!()) + .about(clap::crate_description!()) + .arg( + Arg::with_name("list-sites") + .long("list-sites") + .help("Print available StackExchange sites"), + ) + .arg( + Arg::with_name("site") + .long("site") + .short("s") + .multiple(true) + .number_of_values(1) + .takes_value(true) + .default_value("stackoverflow") + .help("StackExchange site codes to search"), + ) + .arg( + Arg::with_name("limit") + .long("limit") + .short("l") + .number_of_values(1) + .takes_value(true) + .default_value("50") + .validator(|s| s.parse::<u32>().map_err(|e| e.to_string()).map(|_| ())) + .help("Question limit per site query"), + ) + .arg( + Arg::with_name("lucky") + .long("lucky") + .help("Print the top-voted answer of the most relevant question"), + ) + .arg( + Arg::with_name("query") + .multiple(true) + .index(1) + .required(true) + .required_unless("list-sites"), + ) } fn main() { |