Set up a client and basic command infrastructure

This commit is contained in:
Marc Plano-Lesay 2024-10-24 11:55:16 +11:00
parent 56a22203ef
commit 46338adca4
6 changed files with 278 additions and 1 deletions

View file

@ -1,3 +1,45 @@
include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
fn main() {}
use crate::args::Commands;
use anyhow::Result;
use args::ServerCommands;
use clap::Parser;
use commands::server_version::server_version;
use reqwest::header;
mod args;
mod commands;
#[tokio::main]
async fn main() {
let args = args::Opts::parse();
let client = get_client(&args.server_url, &args.api_key).unwrap();
let res = match &args.command {
Commands::Server { server_command } => match server_command {
ServerCommands::Version {} => server_version(&client).await,
},
};
match res {
Ok(_) => {}
Err(e) => println!("Error: {:?}", e),
}
}
fn get_client(url: &str, api_key: &str) -> Result<Client> {
let mut headers = header::HeaderMap::new();
let mut auth_value = header::HeaderValue::from_str(api_key)?;
auth_value.set_sensitive(true);
headers.insert("x-api-key", auth_value);
Ok(Client::new_with_client(
url,
reqwest::Client::builder()
.default_headers(headers)
.build()
.unwrap(),
))
}