nhentairs/src/commands.rs

36 lines
982 B
Rust
Raw Normal View History

2020-09-12 12:26:07 +00:00
mod download;
2023-10-28 00:11:16 +00:00
mod search;
mod view;
2020-09-12 12:26:07 +00:00
use std::env;
use std::path::Path;
use std::process::exit;
pub async fn run() {
let mut args = env::args();
let path = args.next().expect("Cannot get binary path");
let path = Path::new(&path).file_stem().unwrap().to_str().unwrap();
let operation = match args.next() {
2023-10-28 00:11:16 +00:00
Some(operation) => operation,
None => {
eprintln!("Missing operation, run `{} help`", path);
exit(1);
}
2020-09-12 12:26:07 +00:00
};
match operation.as_str() {
"search" => search::run(args).await,
"view" | "show" | "info" => view::run(args).await,
"download" | "dl" => download::run(args).await,
2023-10-28 00:11:16 +00:00
"help" => println!(
r#"Usage: {} search QUERY
2020-09-12 12:26:07 +00:00
or {} info/view/show SAUCE [SAUCE]...
2023-10-28 00:11:16 +00:00
or {} download/dl SAUCE [SAUCE]..."#,
path, path, path
),
2020-09-12 12:26:07 +00:00
_ => {
eprintln!("Unknown operation, run `{} help`", path);
exit(1)
}
};
}