56 lines
1.6 KiB
Rust
56 lines
1.6 KiB
Rust
include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
|
|
|
|
use crate::args::Commands;
|
|
use anyhow::Result;
|
|
use args::{PeopleCommands, ServerCommands};
|
|
use clap::Parser;
|
|
use commands::missing_date_of_birth::missing_date_of_birth;
|
|
use commands::server_version::server_version;
|
|
use commands::sync_date_of_birth::sync_date_of_birth;
|
|
use reqwest::header;
|
|
|
|
mod args;
|
|
mod commands;
|
|
mod utils;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
pretty_env_logger::init();
|
|
|
|
let args = args::Opts::parse();
|
|
|
|
let client = get_client(&args.server_url, &args.api_key).unwrap();
|
|
|
|
let res = match &args.command {
|
|
Commands::People { people_command } => match people_command {
|
|
PeopleCommands::MissingDateOfBirths {} => missing_date_of_birth(&client).await,
|
|
PeopleCommands::SyncDateOfBirths { vcard_file } => {
|
|
sync_date_of_birth(&client, vcard_file, args.dry_run).await
|
|
}
|
|
},
|
|
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(),
|
|
))
|
|
}
|