use clap::{Parser, Subcommand, ValueEnum};
use serde::{Deserialize, Serialize};
#[derive(Parser)]
#[command(name = "toss-api")]
#[command(about = "A Vim-inspired TUI API client", long_about = None)]
pub struct CliArgs {
#[command(subcommand)]
pub command: Option<Commands>,
}
#[derive(Subcommand)]
pub enum Commands {
Send {
#[arg(short, long, default_value = "GET")]
method: Method,
url: String,
#[arg(short, long)]
body: Option<String>,
#[arg(short = 'H', long)]
header: Vec<String>,
#[arg(short, long)]
env: Option<String>,
#[arg(long)]
silent: bool,
#[arg(long)]
json: bool,
#[arg(long)]
headers_only: bool,
#[arg(long)]
offline: bool,
},
Import {
path: String,
#[arg(short = 'u', long, num_args(0..=1), default_missing_value = "interactive")]
base_url: Option<String>,
},
Parse {
path: String,
#[arg(short = 'u', long, num_args(0..=1), default_missing_value = "interactive")]
base_url: Option<String>,
},
Collections {
#[command(subcommand)]
command: CollectionsCommands,
},
Run {
collection: String,
request: String,
#[arg(short, long)]
env: Option<String>,
#[arg(long)]
silent: bool,
#[arg(long)]
json: bool,
},
Env {
#[command(subcommand)]
command: EnvCommands,
},
}
#[derive(Subcommand)]
pub enum CollectionsCommands {
List,
Show {
name: String,
},
}
#[derive(Subcommand)]
pub enum EnvCommands {
List,
Show {
collection: String,
},
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug, Serialize, Deserialize)]
#[value(rename_all = "UPPERCASE")]
pub enum Method {
Get,
Post,
Put,
Patch,
Delete,
}
impl From<Method> for reqwest::Method {
fn from(method: Method) -> Self {
match method {
Method::Get => reqwest::Method::GET,
Method::Post => reqwest::Method::POST,
Method::Put => reqwest::Method::PUT,
Method::Patch => reqwest::Method::PATCH,
Method::Delete => reqwest::Method::DELETE,
}
}
}