imgurs/src/cli/parse.rs

55 lines
1.2 KiB
Rust
Raw Normal View History

2022-01-22 21:14:26 +00:00
use clap::{AppSettings, Parser, Subcommand};
2022-01-22 21:02:51 +00:00
use imgurs::api::configuration::ImgurHandle;
use crate::cli::*;
const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION");
#[derive(Parser, Debug)]
#[clap(
name = "imgur",
about = "Imgur API CLI", long_about = None,
version = VERSION.unwrap_or("unknown")
)]
struct Cli {
#[clap(subcommand)]
command: Commands,
}
#[derive(Subcommand, Debug)]
enum Commands {
#[clap(about = "Get API Rate Limit")]
Credits,
#[clap(
setting(AppSettings::ArgRequiredElseHelp),
about = "Upload image to imgur"
)]
2022-01-22 21:14:26 +00:00
Upload { path: String },
2022-01-22 21:02:51 +00:00
#[clap(
setting(AppSettings::ArgRequiredElseHelp),
about = "Upload image to imgur"
)]
2022-01-22 21:14:26 +00:00
Delete { delete_hash: String },
2022-01-22 21:02:51 +00:00
}
pub async fn parse(client: ImgurHandle) {
let args = Cli::parse();
match &args.command {
Commands::Credits => {
2022-01-22 21:14:26 +00:00
credits::credits(client).await;
2022-01-22 21:02:51 +00:00
}
Commands::Upload { path } => {
2022-01-22 21:14:26 +00:00
upload_image::upload_image(client, path).await;
2022-01-22 21:02:51 +00:00
}
Commands::Delete { delete_hash } => {
2022-01-22 21:14:26 +00:00
delete_image::delete_image(client, delete_hash.to_string()).await;
2022-01-22 21:02:51 +00:00
}
}
}