use clap::Subcommand;
pub mod account;
pub use account::Account;
pub mod address;
pub use address::{Address, AddressResponse, GetExpiry, GetInfo, GetPublicInfo, IsAvailable};
pub mod dns;
pub use dns::Dns;
pub mod email;
pub use email::Email;
pub mod now;
pub use now::Now;
pub mod pastebin;
pub use pastebin::Pastebin;
pub mod purl;
pub use purl::Purl;
pub mod status;
pub use status::Status;
pub mod theme;
pub use theme::Theme;
pub mod web;
pub use web::Web;
pub mod weblog;
pub use weblog::Weblog;
fn get<T: serde::de::DeserializeOwned>(url: &str) -> Result<T, reqwest::Error> {
reqwest::blocking::Client::new()
.get(format!("https://api.omg.lol/{}", url))
.send()?
.error_for_status()?
.json::<T>()
}
fn get_auth<T: serde::de::DeserializeOwned>(api_key: &str, url: &str) -> Result<T, reqwest::Error> {
reqwest::blocking::Client::new()
.get(format!("https://api.omg.lol/{}", url))
.header(reqwest::header::AUTHORIZATION, format!("Bearer {api_key}"))
.send()?
.error_for_status()?
.json::<T>()
}
#[derive(Subcommand)]
pub enum Commands {
#[clap(visible_aliases = &["ac"])]
Account {
#[clap(subcommand)]
command: Account,
},
#[clap(visible_aliases = &["a"])]
Address {
#[clap(subcommand)]
command: Address,
},
Auth {
name: String,
},
#[clap(visible_aliases = &["dir"])]
Directory,
#[clap(visible_aliases = &["d"])]
Dns {
#[clap(subcommand)]
command: Dns,
},
#[clap(visible_aliases = &["e"])]
Email {
#[clap(subcommand)]
command: Email,
},
#[clap(visible_aliases = &["n"])]
Now {
#[clap(subcommand)]
command: Now,
},
#[clap(visible_aliases = &["p"])]
Pastebin {
#[clap(subcommand)]
command: Pastebin,
},
#[clap(visible_aliases = &["pr"])]
Preferences {
owner: String,
item: String,
value: String,
},
#[clap(visible_aliases = &["u"])]
Purl {
#[clap(subcommand)]
command: Purl,
},
Service,
#[clap(visible_aliases = &["s"])]
Status {
#[clap(subcommand)]
command: Status,
},
Switch {
address: Option<String>,
},
#[clap(visible_aliases = &["t"])]
Theme {
#[clap(subcommand)]
command: Theme,
},
#[clap(visible_aliases = &["w"])]
Web {
#[clap(subcommand)]
command: Web,
},
#[clap(visible_aliases = &["b"])]
Weblog {
#[clap(subcommand)]
command: Weblog,
},
}
impl Commands {
pub fn process(
&self,
_address: &str,
api_key: &str,
) -> Result<CommandResponse, reqwest::Error> {
match self {
Commands::Account { command } => {
command.process();
Ok(CommandResponse::Todo(()))
}
Commands::Address { command } => {
Ok(CommandResponse::Address(command.process(api_key)?))
}
Commands::Auth { name } => unreachable!("{name}"),
Commands::Directory => todo!(),
Commands::Dns { command } => todo!("{command:?}"),
Commands::Email { command } => todo!("{command:?}"),
Commands::Now { command } => todo!("{command:?}"),
Commands::Pastebin { command } => todo!("{command:?}"),
Commands::Preferences { owner, item, value } => todo!("{owner}, {item}, {value}"),
Commands::Purl { command } => todo!("{command:?}"),
Commands::Service => todo!(),
Commands::Status { command } => todo!("{command:?}"),
Commands::Switch { address: _ } => todo!(),
Commands::Theme { command } => todo!("{command:?}"),
Commands::Web { command } => todo!("{command:?}"),
Commands::Weblog { command } => todo!("{command:?}"),
}
}
}
#[derive(Debug)]
pub enum CommandResponse {
Todo(()),
Address(AddressResponse),
}