use argh::FromArgs;
mod version;
mod request;
use crate::request::request;
use crate::version::check_version;
#[derive(FromArgs)]
struct Args {
#[argh(option, short = 'm')]
method: String,
#[argh(option, short = 'u')]
url: String,
#[argh(option, default = "true")]
headers: bool,
#[argh(option, short = 'b')]
body: Option<String>,
}
#[tokio::main]
async fn main() {
check_version().await;
match start().await {
Ok(()) => {}
Err(e) => {
eprintln!("{e}");
std::process::exit(1);
}
}
}
async fn start() -> Result<(), request::Error> {
let args: Args = argh::from_env();
let mut print_headers: bool = false;
let method: String = args.method;
let body: Vec<u8> = args.body.as_deref().map_or(Vec::new(), |s| s.as_bytes().to_vec());
let url = args.url;
if args.headers {
print_headers = true;
}
request(&method, &url, &body, print_headers).await?;
Ok(())
}