diff --git a/src/cli.rs b/src/cli.rs index 5230178..91373db 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,5 +1,5 @@ -use crate::commands::*; -use clap::{Parser, Subcommand}; +use crate::commands::Commands; +use clap::Parser; #[derive(Parser)] pub struct Cli { @@ -13,115 +13,3 @@ pub struct Cli { #[arg(short, long, action = clap::ArgAction::Count)] pub verbose: u8, } - -// TODO: allow content fields for some commands to provide filepaths, using the content of the file instead - -#[derive(Subcommand)] -pub enum Commands { - /// Get information and make changes to your account - Account { - /// Email of your omg.lol account, needed for Account commands only - #[clap(short, long, global = true)] - email: Option, - #[clap(subcommand)] - command: Account, - }, - /// Get information and make changes to your addresses - Address { - /// omg.lol address to interact with - #[clap(short, long, global = true)] - address: Option, - #[clap(subcommand)] - command: Address, - }, - /// Save your omg.lol API key to the config.json (Rather than using the OMGLOL_API_KEY environment variable) - Auth { - /// API key to save to config.json - api_key: String, - }, - /// Get the address directory, consisting of addresses that have opted-in to be listed - Directory, - /// Adjust the switchboard / DNS records for your omg.lol address - Dns { - /// omg.lol address to interact with - #[clap(short, long, global = true)] - address: Option, - #[clap(subcommand)] - command: Dns, - }, - /// Manage the email configuration for an omg.lol address - Email { - /// omg.lol address to interact with - #[clap(short, long, global = true)] - address: Option, - #[clap(subcommand)] - command: Email, - }, - /// Manage your /now page - Now { - /// omg.lol address to interact with - #[clap(short, long, global = true)] - address: Option, - #[clap(subcommand)] - command: Now, - }, - /// Manage the pastebin for an omg.lol address - Pastebin { - /// omg.lol address to interact with - #[clap(short, long, global = true)] - address: Option, - #[clap(subcommand)] - command: Pastebin, - }, - /// Manage preferences for omg.lol accounts, addresses and objects - Preferences { - /// Account to change settings for - owner: String, - /// ID of setting to update - item: String, - /// Value to set "item" to - value: String, - }, - /// Manage PURLs (Persistent URLs) for your omg.lol address - Purl { - /// omg.lol address to interact with - #[clap(short, long, global = true)] - address: Option, - #[clap(subcommand)] - command: Purl, - }, - /// Get service information about omg.lol - Service, - /// Manage the statuslog for an omg.lol address - Status { - /// omg.lol address to interact with - #[clap(short, long, global = true)] - address: Option, - #[clap(subcommand)] - command: Status, - }, - /// Manage omg.lol profile themes - Theme { - /// omg.lol address to interact with - #[clap(short, long, global = true)] - address: Option, - #[clap(subcommand)] - command: Theme, - }, - /// Manage profile page and web stuff for an omg.lol address - Web { - /// omg.lol address to interact with - #[clap(short, long, global = true)] - address: Option, - #[clap(subcommand)] - command: Web, - }, - /// Manage the weblog for an omg.lol address - Weblog { - /// omg.lol address to interact with - #[clap(short, long, global = true)] - address: Option, - #[clap(subcommand)] - command: Weblog, - }, -} diff --git a/src/commands/account.rs b/src/commands/account.rs index 24ae6ce..c98262f 100644 --- a/src/commands/account.rs +++ b/src/commands/account.rs @@ -28,3 +28,18 @@ pub enum Account { json_data: String, }, } + +impl Account { + pub fn process(&self, _email: &str) { + match self { + Account::GetInfo => todo!(), + Account::GetAddresses => todo!(), + Account::GetName => todo!(), + Account::SetName { name: _ } => todo!(), + Account::GetSessions => todo!(), + Account::RemoveSession { session_id: _ } => todo!(), + Account::GetSettings => todo!(), + Account::SetSettings { json_data: _ } => todo!(), + } + } +} diff --git a/src/commands/address.rs b/src/commands/address.rs index a187e32..13e0f0d 100644 --- a/src/commands/address.rs +++ b/src/commands/address.rs @@ -11,3 +11,14 @@ pub enum Address { ///Get comprehensive information about an address GetInfo, } + +impl Address { + pub fn process(&self) { + match self { + Address::IsAvailable => todo!(), + Address::GetExpiry => todo!(), + Address::GetPublicInfo => todo!(), + Address::GetInfo => todo!(), + } + } +} diff --git a/src/commands/dns.rs b/src/commands/dns.rs index 15db619..553547f 100644 --- a/src/commands/dns.rs +++ b/src/commands/dns.rs @@ -20,3 +20,14 @@ pub enum Dns { id: String, }, } + +impl Dns { + pub fn process(&self) { + match self { + Dns::GetRecords => todo!(), + Dns::AddRecord { json_data } => todo!(), + Dns::UpdateRecord { json_data } => todo!(), + Dns::DeleteRecord { id } => todo!(), + } + } +} diff --git a/src/commands/email.rs b/src/commands/email.rs index 526a121..328ecbb 100644 --- a/src/commands/email.rs +++ b/src/commands/email.rs @@ -10,3 +10,12 @@ pub enum Email { json_data: String, }, } + +impl Email { + pub fn process(&self) { + match self { + Email::GetForwards => todo!(), + Email::SetForwards { json_data } => todo!(), + } + } +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 2387efb..b62496c 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,3 +1,5 @@ +use clap::Subcommand; + pub mod account; pub use account::Account; pub mod address; @@ -20,3 +22,138 @@ pub mod web; pub use web::Web; pub mod weblog; pub use weblog::Weblog; + +// TODO: allow content fields for some commands to provide filepaths, using the content of the file instead +#[derive(Subcommand)] +pub enum Commands { + /// Get information and make changes to your account + Account { + /// Email of your omg.lol account, needed for Account commands only + #[clap(short, long, global = true)] + email: String, + #[clap(subcommand)] + command: Account, + }, + /// Get information and make changes to your addresses + Address { + /// omg.lol address to interact with + #[clap(short, long, global = true)] + address: Option, + #[clap(subcommand)] + command: Address, + }, + /// Save your omg.lol API key to the config.json (Rather than using the OMGLOL_API_KEY environment variable) + Auth { + /// API key to save to config.json + api_key: String, + }, + /// Get the address directory, consisting of addresses that have opted-in to be listed + Directory, + /// Adjust the switchboard / DNS records for your omg.lol address + Dns { + /// omg.lol address to interact with + #[clap(short, long, global = true)] + address: Option, + #[clap(subcommand)] + command: Dns, + }, + /// Manage the email configuration for an omg.lol address + Email { + /// omg.lol address to interact with + #[clap(short, long, global = true)] + address: Option, + #[clap(subcommand)] + command: Email, + }, + /// Manage your /now page + Now { + /// omg.lol address to interact with + #[clap(short, long, global = true)] + address: Option, + #[clap(subcommand)] + command: Now, + }, + /// Manage the pastebin for an omg.lol address + Pastebin { + /// omg.lol address to interact with + #[clap(short, long, global = true)] + address: Option, + #[clap(subcommand)] + command: Pastebin, + }, + /// Manage preferences for omg.lol accounts, addresses and objects + Preferences { + /// Account to change settings for + owner: String, + /// ID of setting to update + item: String, + /// Value to set "item" to + value: String, + }, + /// Manage PURLs (Persistent URLs) for your omg.lol address + Purl { + /// omg.lol address to interact with + #[clap(short, long, global = true)] + address: Option, + #[clap(subcommand)] + command: Purl, + }, + /// Get service information about omg.lol + Service, + /// Manage the statuslog for an omg.lol address + Status { + /// omg.lol address to interact with + #[clap(short, long, global = true)] + address: Option, + #[clap(subcommand)] + command: Status, + }, + /// Manage omg.lol profile themes + Theme { + /// omg.lol address to interact with + #[clap(short, long, global = true)] + address: Option, + #[clap(subcommand)] + command: Theme, + }, + /// Manage profile page and web stuff for an omg.lol address + Web { + /// omg.lol address to interact with + #[clap(short, long, global = true)] + address: Option, + #[clap(subcommand)] + command: Web, + }, + /// Manage the weblog for an omg.lol address + Weblog { + /// omg.lol address to interact with + #[clap(short, long, global = true)] + address: Option, + #[clap(subcommand)] + command: Weblog, + }, +} + +impl Commands { + fn process(&self) { + match self { + Commands::Account { email, command } => { + command.process(email); + } + Commands::Address { address, command } => todo!(), + Commands::Auth { api_key } => todo!(), + Commands::Directory => todo!(), + Commands::Dns { address, command } => todo!(), + Commands::Email { address, command } => todo!(), + Commands::Now { address, command } => todo!(), + Commands::Pastebin { address, command } => todo!(), + Commands::Preferences { owner, item, value } => todo!(), + Commands::Purl { address, command } => todo!(), + Commands::Service => todo!(), + Commands::Status { address, command } => todo!(), + Commands::Theme { address, command } => todo!(), + Commands::Web { address, command } => todo!(), + Commands::Weblog { address, command } => todo!(), + } + } +} diff --git a/src/commands/now.rs b/src/commands/now.rs index 1e56fb7..1fcaf04 100644 --- a/src/commands/now.rs +++ b/src/commands/now.rs @@ -15,3 +15,13 @@ pub enum Now { listed: bool, }, } + +impl Now { + pub fn process(&self) { + match self { + Now::Get => todo!(), + Now::List => todo!(), + Now::Set { content, listed } => todo!(), + } + } +} diff --git a/src/commands/pastebin.rs b/src/commands/pastebin.rs index 9c31dee..95d2710 100644 --- a/src/commands/pastebin.rs +++ b/src/commands/pastebin.rs @@ -24,3 +24,15 @@ pub enum Pastebin { name: String, }, } + +impl Pastebin { + pub fn process(&self) { + match self { + Pastebin::Get { name } => todo!(), + Pastebin::GetAll => todo!(), + Pastebin::GetAllPublic => todo!(), + Pastebin::Set { name, content } => todo!(), + Pastebin::Delete { name } => todo!(), + } + } +} diff --git a/src/commands/purl.rs b/src/commands/purl.rs index 4f09145..e1d9a3b 100644 --- a/src/commands/purl.rs +++ b/src/commands/purl.rs @@ -22,3 +22,14 @@ pub enum Purl { name: String, }, } + +impl Purl { + pub fn process(&self) { + match self { + Purl::Create { name, url } => todo!(), + Purl::Get { name } => todo!(), + Purl::List => todo!(), + Purl::Delete { name } => todo!(), + } + } +} diff --git a/src/commands/status.rs b/src/commands/status.rs index 7839a78..3b9e1ef 100644 --- a/src/commands/status.rs +++ b/src/commands/status.rs @@ -45,3 +45,19 @@ pub enum Status { /// Get the most recent statuslog entries across omg.lol Timeline, } + +impl Status { + pub fn process(&self) { + match self { + Status::Get { id } => todo!(), + Status::GetAll => todo!(), + Status::Create { emoji, content, external_url } => todo!(), + Status::EasyCreate { status } => todo!(), + Status::Update { id, emoji, content } => todo!(), + Status::GetBio => todo!(), + Status::SetBio { content } => todo!(), + Status::GetAllHistorical => todo!(), + Status::Timeline => todo!(), + } + } +} diff --git a/src/commands/theme.rs b/src/commands/theme.rs index 4784626..49e3ef2 100644 --- a/src/commands/theme.rs +++ b/src/commands/theme.rs @@ -15,3 +15,13 @@ pub enum Theme { id: String, }, } + +impl Theme { + pub fn process(&self) { + match self { + Theme::List => todo!(), + Theme::Info { id } => todo!(), + Theme::Preview { id } => todo!(), + } + } +} diff --git a/src/commands/web.rs b/src/commands/web.rs index bd35e09..15db3bf 100644 --- a/src/commands/web.rs +++ b/src/commands/web.rs @@ -20,3 +20,13 @@ pub enum Web { // Eg: #[arg(value_parser = |arg: &str| -> Result {Ok(Duration::from_secs(arg.parse()?))})] }, } + +impl Web { + pub fn process(&self) { + match self { + Web::Get => todo!(), + Web::Set { content: _, publish: _ } => todo!(), + Web::SetPFP { image: _ } => todo!(), + } + } +} diff --git a/src/commands/weblog.rs b/src/commands/weblog.rs index 2d86610..60875a8 100644 --- a/src/commands/weblog.rs +++ b/src/commands/weblog.rs @@ -36,3 +36,19 @@ pub enum Weblog { content: String, }, } + +impl Weblog { + pub fn process(&self, _address: &Option) { + match self { + Weblog::Get { id: _ } => todo!(), + Weblog::Latest => todo!(), + Weblog::GetAll => todo!(), + Weblog::Create { content: _ } => todo!(), + Weblog::Delete { id: _ } => todo!(), + Weblog::GetConfig => todo!(), + Weblog::SetConfig { content: _ } => todo!(), + Weblog::GetTemplate => todo!(), + Weblog::SetTemplate { content: _ } => todo!(), + } + } +} diff --git a/src/main.rs b/src/main.rs index 983aedf..22356fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use std::fs::read_to_string; mod cli; -use cli::{Cli, Commands}; +use cli::Cli; mod commands; #[derive(Default, Deserialize, Serialize)] @@ -17,7 +17,7 @@ struct Config { fn main() -> anyhow::Result<()> { let cli = Cli::parse(); - if let Some(Commands::Auth { api_key }) = cli.command { + if let Some(commands::Commands::Auth { api_key }) = cli.command { match save_api_key(&api_key) { Ok(_) => std::process::exit(0), Err(_) => std::process::exit(1),