diff --git a/CHANGELOG.md b/CHANGELOG.md index f386e36..da3e0d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Address input parameter for fn `process` in `impl`s +- Derive `Debug` for subcommands in `/src` ### Changed +- fn `process` in `impl`s takes `&str` instead of `&Option` + ### Deprecated ### Removed @@ -21,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security -## 0.1.0 - 2023-05-08 +## [0.1.0] - 2023-05-08 ### Added diff --git a/Cargo.toml b/Cargo.toml index 82c2712..c907a34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,10 @@ license = "Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { version = "4.2.7", features = ["derive"] } +clap = { version = "4.4.1", features = ["derive"] } +const_format = "0.2.31" +reqwest = { version = "0.11.20", features = ["blocking", "json"] } +serde = { version = "1.0.188", features = ["derive"] } +serde_json = "1.0.105" +structstruck = "0.4.1" +thiserror = "1.0.47" diff --git a/src/account.rs b/src/account.rs index c98262f..b1f7a0a 100644 --- a/src/account.rs +++ b/src/account.rs @@ -1,45 +1,66 @@ use clap::Subcommand; -#[derive(Subcommand)] +#[derive(Debug, Subcommand)] pub enum Account { /// Get information about your account - GetInfo, + GetInfo { + /// Email of your omg.lol account + email: String, + }, /// Get all addresses associated with your account - GetAddresses, + GetAddresses { + /// Email of your omg.lol account + email: String, + }, /// Get the name associated with your account - GetName, + GetName { + /// Email of your omg.lol account + email: String, + }, /// Update the name associated with your account SetName { + /// Email of your omg.lol account + email: String, /// Name to set for your account name: String, }, /// Get all sessions associated with your account - GetSessions, + GetSessions { + /// Email of your omg.lol account + email: String, + }, /// Delete a session from your account RemoveSession { + /// Email of your omg.lol account + email: String, /// ID of the session to remove session_id: String, }, /// Get settings associated with your account - GetSettings, + GetSettings { + /// Email of your omg.lol account + email: String, + }, /// Update settings associated with your account SetSettings { + /// Email of your omg.lol account + email: String, /// Temporary JSON data input json_data: String, }, } impl Account { - pub fn process(&self, _email: &str) { + pub fn process(&self) { 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!(), + Account::GetInfo { email: _ } => todo!(), + Account::GetAddresses { email: _ } => todo!(), + Account::GetName { email: _ } => todo!(), + Account::SetName { email: _, name: _ } => todo!(), + Account::GetSessions { email: _ } => todo!(), + Account::RemoveSession { email: _, session_id: _ } => todo!(), + Account::GetSettings { email: _ } => todo!(), + Account::SetSettings { email: _, json_data: _ } => todo!(), } } } diff --git a/src/address.rs b/src/address.rs index b35ab28..d750897 100644 --- a/src/address.rs +++ b/src/address.rs @@ -1,19 +1,34 @@ use clap::Subcommand; +use serde::Deserialize; -#[derive(Subcommand)] +use crate::{get, get_auth}; + +#[derive(Debug, Subcommand)] pub enum Address { /// Get information about the availability of an address - IsAvailable, + IsAvailable { + /// Address to get availability of + address: String, + }, /// Get the expiration date for an address - GetExpiry, + GetExpiry { + /// Address to get availability of + address: String, + }, /// Get limited (public) information about an address (no auth required) - GetPublicInfo, - ///Get comprehensive information about an address - GetInfo, + GetPublicInfo { + /// Address to get availability of + address: String, + }, + /// Get comprehensive information about an address + GetInfo { + /// Address to get availability of + address: String, + }, } impl Address { - pub fn process(&self, _address: &Option) { + pub fn process(&self, api_key: &str) -> Result { match self { Address::IsAvailable => todo!(), Address::GetExpiry => todo!(), diff --git a/src/dns.rs b/src/dns.rs index 59c1abb..495be00 100644 --- a/src/dns.rs +++ b/src/dns.rs @@ -1,6 +1,6 @@ use clap::Subcommand; -#[derive(Subcommand)] +#[derive(Debug, Subcommand)] pub enum Dns { /// Get a list of all your DNS records GetRecords, @@ -22,7 +22,7 @@ pub enum Dns { } impl Dns { - pub fn process(&self, _address: &Option) { + pub fn process(&self, _address: &str) { match self { Dns::GetRecords => todo!(), Dns::AddRecord { json_data: _ } => todo!(), diff --git a/src/email.rs b/src/email.rs index c445a1c..f9aceed 100644 --- a/src/email.rs +++ b/src/email.rs @@ -1,6 +1,6 @@ use clap::Subcommand; -#[derive(Subcommand)] +#[derive(Debug, Subcommand)] pub enum Email { /// Get forwarding address(es) GetForwards, @@ -12,7 +12,7 @@ pub enum Email { } impl Email { - pub fn process(&self, _address: &Option) { + pub fn process(&self, _address: &str) { match self { Email::GetForwards => todo!(), Email::SetForwards { json_data: _ } => todo!(), diff --git a/src/lib.rs b/src/lib.rs index be0d89b..05de81c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ use clap::Subcommand; pub mod account; pub use account::Account; pub mod address; -pub use address::Address; +pub use address::{Address, AddressResponse, GetExpiry, GetInfo, GetPublicInfo, IsAvailable}; pub mod dns; pub use dns::Dns; pub mod email; @@ -28,56 +28,38 @@ pub use weblog::Weblog; 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, overrides config and env. var: (OMGLOL_USERNAME) - #[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 env. var: OMGLOL_API_KEY) + /// Save omg.lol API key to config.toml, will prompt (vs env. var: OMGLOL_API_KEY) Auth { - /// API key to save to config.json - api_key: String, + /// Linked omg.lol name for API key + name: 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, overrides config and env. var: (OMGLOL_USERNAME) - #[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, overrides config and env. var: (OMGLOL_USERNAME) - #[clap(short, long, global = true)] - address: Option, #[clap(subcommand)] command: Email, }, /// Manage your /now page Now { - /// omg.lol address to interact with, overrides config and env. var: (OMGLOL_USERNAME) - #[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, overrides config and env. var: (OMGLOL_USERNAME) - #[clap(short, long, global = true)] - address: Option, #[clap(subcommand)] command: Pastebin, }, @@ -92,9 +74,6 @@ pub enum Commands { }, /// Manage PURLs (Persistent URLs) for your omg.lol address Purl { - /// omg.lol address to interact with, overrides config and env. var: (OMGLOL_USERNAME) - #[clap(short, long, global = true)] - address: Option, #[clap(subcommand)] command: Purl, }, @@ -102,33 +81,26 @@ pub enum Commands { Service, /// Manage the statuslog for an omg.lol address Status { - /// omg.lol address to interact with, overrides config and env. var: (OMGLOL_USERNAME) - #[clap(short, long, global = true)] - address: Option, #[clap(subcommand)] command: Status, }, + /// Set a default omg.lol address (and API key) from saved addresses + Switch { + /// new default omg.lol address, leave blank to list available addresses + address: Option, + }, /// Manage omg.lol profile themes Theme { - /// omg.lol address to interact with, overrides config and env. var: (OMGLOL_USERNAME) - #[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, overrides config and env. var: (OMGLOL_USERNAME) - #[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, overrides config and env. var: (OMGLOL_USERNAME) - #[clap(short, long, global = true)] - address: Option, #[clap(subcommand)] command: Weblog, }, @@ -136,23 +108,39 @@ pub enum Commands { impl Commands { // TBD: Is there a more idiomatic / succinct approach to this? - pub fn process(&self, _address: &Option) { + pub fn process( + &self, + _address: &str, + api_key: &str, + ) -> Result { match self { - Commands::Account { email, command } => command.process(email), - Commands::Address { address, command } => command.process(address), - Commands::Auth { api_key: _ } => todo!(), + 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 { address, command } => command.process(address), - Commands::Email { address, command } => command.process(address), - Commands::Now { address, command } => command.process(address), - Commands::Pastebin { address, command } => command.process(address), - Commands::Preferences { owner: _, item: _, value: _ } => todo!(), - Commands::Purl { address, command } => command.process(address), + 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 { address, command } => command.process(address), - Commands::Theme { address, command } => command.process(address), - Commands::Web { address, command } => command.process(address), - Commands::Weblog { address, command } => command.process(address), + 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), +} diff --git a/src/now.rs b/src/now.rs index 4cd3650..5c8e483 100644 --- a/src/now.rs +++ b/src/now.rs @@ -1,6 +1,6 @@ use clap::Subcommand; -#[derive(Subcommand)] +#[derive(Debug, Subcommand)] pub enum Now { /// Get the /now page for an address Get, @@ -17,7 +17,7 @@ pub enum Now { } impl Now { - pub fn process(&self, _address: &Option) { + pub fn process(&self, _address: &str) { match self { Now::Get => todo!(), Now::List => todo!(), diff --git a/src/pastebin.rs b/src/pastebin.rs index 69ffd50..6533416 100644 --- a/src/pastebin.rs +++ b/src/pastebin.rs @@ -1,6 +1,6 @@ use clap::Subcommand; -#[derive(Subcommand)] +#[derive(Debug, Subcommand)] pub enum Pastebin { /// Get a specific paste for an omg.lol address Get { @@ -26,7 +26,7 @@ pub enum Pastebin { } impl Pastebin { - pub fn process(&self, _address: &Option) { + pub fn process(&self, _address: &str) { match self { Pastebin::Get { name: _ } => todo!(), Pastebin::GetAll => todo!(), diff --git a/src/purl.rs b/src/purl.rs index b8c0b89..b5a27a5 100644 --- a/src/purl.rs +++ b/src/purl.rs @@ -1,6 +1,6 @@ use clap::Subcommand; -#[derive(Subcommand)] +#[derive(Debug, Subcommand)] pub enum Purl { /// Create a new PURL for an omg.lol address Create { @@ -24,7 +24,7 @@ pub enum Purl { } impl Purl { - pub fn process(&self, _address: &Option) { + pub fn process(&self, _address: &str) { match self { Purl::Create { name: _, url: _ } => todo!(), Purl::Get { name: _ } => todo!(), diff --git a/src/status.rs b/src/status.rs index b8f1e0a..9676a76 100644 --- a/src/status.rs +++ b/src/status.rs @@ -1,6 +1,6 @@ use clap::Subcommand; -#[derive(Subcommand)] +#[derive(Debug, Subcommand)] pub enum Status { /// Get a single statuslog entry for an omg.lol address Get { @@ -47,7 +47,7 @@ pub enum Status { } impl Status { - pub fn process(&self, _address: &Option) { + pub fn process(&self, _address: &str) { match self { Status::Get { id: _ } => todo!(), Status::GetAll => todo!(), diff --git a/src/theme.rs b/src/theme.rs index 8ea9e2b..b54b3f5 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -1,6 +1,6 @@ use clap::Subcommand; -#[derive(Subcommand)] +#[derive(Debug, Subcommand)] pub enum Theme { /// List available omg.lol profile themes List, @@ -17,7 +17,7 @@ pub enum Theme { } impl Theme { - pub fn process(&self, _address: &Option) { + pub fn process(&self, _address: &str) { match self { Theme::List => todo!(), Theme::Info { id: _ } => todo!(), diff --git a/src/web.rs b/src/web.rs index 582a0d4..c10f5b1 100644 --- a/src/web.rs +++ b/src/web.rs @@ -1,6 +1,6 @@ use clap::Subcommand; -#[derive(Subcommand)] +#[derive(Debug, Subcommand)] pub enum Web { /// Get web content and information for an omg.lol address Get, @@ -22,7 +22,7 @@ pub enum Web { } impl Web { - pub fn process(&self, _address: &Option) { + pub fn process(&self, _address: &str) { match self { Web::Get => todo!(), Web::Set { content: _, publish: _ } => todo!(), diff --git a/src/weblog.rs b/src/weblog.rs index 60875a8..a280ca1 100644 --- a/src/weblog.rs +++ b/src/weblog.rs @@ -1,6 +1,6 @@ use clap::Subcommand; -#[derive(Subcommand)] +#[derive(Debug, Subcommand)] pub enum Weblog { /// Get a specific weblog entry for an omg.lol address Get { @@ -38,7 +38,7 @@ pub enum Weblog { } impl Weblog { - pub fn process(&self, _address: &Option) { + pub fn process(&self, _address: &str) { match self { Weblog::Get { id: _ } => todo!(), Weblog::Latest => todo!(),