hanimers/src/main.rs

79 lines
2.6 KiB
Rust

mod commands;
mod structs;
mod utils;
use clap::{App, AppSettings, Arg, SubCommand};
extern crate tokio;
fn main() {
let matches = App::new("hanimers")
.about("hanime.tv downloader in rust")
// let's hope i remember to bump the version xd
.version("0.1.1")
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(
SubCommand::with_name("search")
.arg(
Arg::with_name("tags")
.long("tags")
.short("t")
.takes_value(true)
.use_delimiter(true)
.case_insensitive(true)
.possible_values(&commands::AVALIABLE_TAGS)
).arg(
Arg::with_name("broad")
.long("broad")
.short("b")
.help("More results, but less accurate. Videos will match if they contain any selected tag rather than all selected tags.")
).arg(
Arg::with_name("query")
.takes_value(true)
.multiple(true)
.help("Search query")
)
)
.subcommand(
SubCommand::with_name("view")
.aliases(&["info", "show"])
.arg(
Arg::with_name("id")
.takes_value(true)
.multiple(true)
.required(true)
)
)
.subcommand(
SubCommand::with_name("download")
.alias("dl")
.arg(
Arg::with_name("print")
.long("print")
.short("p")
.help("Print the URL to download only")
).arg(
Arg::with_name("resolution")
.long("resolution")
.short("r")
.help("Set preferred resolution")
.takes_value(true)
).arg(
Arg::with_name("id")
.takes_value(true)
.multiple(true)
.required(true)
)
)
.get_matches();
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
match matches.subcommand() {
("search", Some(sub_m)) => runtime.block_on(commands::search(sub_m)),
("view", Some(sub_m)) => runtime.block_on(commands::view(sub_m)),
("download", Some(sub_m)) => runtime.block_on(commands::download(sub_m)),
_ => panic!("AppSettings::SubcommandRequiredElseHelp do your job please")
};
}