From 6540c41f1fd51a5291f4c71bac75fcb1eceb3e40 Mon Sep 17 00:00:00 2001 From: Aadi Desai <21363892+supleed2@users.noreply.github.com> Date: Tue, 25 Apr 2023 00:52:06 +0100 Subject: [PATCH] Move commands into separate submodules Submodules are located under commands module --- src/cli.rs | 270 ++------------------------------------- src/commands/account.rs | 30 +++++ src/commands/address.rs | 13 ++ src/commands/dns.rs | 22 ++++ src/commands/email.rs | 12 ++ src/commands/mod.rs | 22 ++++ src/commands/now.rs | 17 +++ src/commands/pastebin.rs | 26 ++++ src/commands/purl.rs | 24 ++++ src/commands/status.rs | 47 +++++++ src/commands/theme.rs | 17 +++ src/commands/web.rs | 22 ++++ src/commands/weblog.rs | 38 ++++++ src/main.rs | 3 +- 14 files changed, 302 insertions(+), 261 deletions(-) create mode 100644 src/commands/account.rs create mode 100644 src/commands/address.rs create mode 100644 src/commands/dns.rs create mode 100644 src/commands/email.rs create mode 100644 src/commands/mod.rs create mode 100644 src/commands/now.rs create mode 100644 src/commands/pastebin.rs create mode 100644 src/commands/purl.rs create mode 100644 src/commands/status.rs create mode 100644 src/commands/theme.rs create mode 100644 src/commands/web.rs create mode 100644 src/commands/weblog.rs diff --git a/src/cli.rs b/src/cli.rs index 308c0ff..5230178 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,3 +1,4 @@ +use crate::commands::*; use clap::{Parser, Subcommand}; #[derive(Parser)] @@ -18,7 +19,7 @@ pub struct Cli { #[derive(Subcommand)] pub enum Commands { /// Get information and make changes to your account - Account{ // TODO: include or not? + Account { /// Email of your omg.lol account, needed for Account commands only #[clap(short, long, global = true)] email: Option, @@ -26,7 +27,7 @@ pub enum Commands { command: Account, }, /// Get information and make changes to your addresses - Address{ + Address { /// omg.lol address to interact with #[clap(short, long, global = true)] address: Option, @@ -41,12 +42,12 @@ pub enum Commands { /// 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 { + Dns { /// omg.lol address to interact with #[clap(short, long, global = true)] address: Option, #[clap(subcommand)] - command: DNS, + command: Dns, }, /// Manage the email configuration for an omg.lol address Email { @@ -73,7 +74,7 @@ pub enum Commands { command: Pastebin, }, /// Manage preferences for omg.lol accounts, addresses and objects - Preferences{ // TODO: include or not? + Preferences { /// Account to change settings for owner: String, /// ID of setting to update @@ -82,15 +83,15 @@ pub enum Commands { value: String, }, /// Manage PURLs (Persistent URLs) for your omg.lol address - PURL { + Purl { /// omg.lol address to interact with #[clap(short, long, global = true)] address: Option, #[clap(subcommand)] - command: PURL, + command: Purl, }, /// Get service information about omg.lol - Service, // TODO: include or not? + Service, /// Manage the statuslog for an omg.lol address Status { /// omg.lol address to interact with @@ -100,7 +101,7 @@ pub enum Commands { command: Status, }, /// Manage omg.lol profile themes - Theme { // TODO: include or not? + Theme { /// omg.lol address to interact with #[clap(short, long, global = true)] address: Option, @@ -124,254 +125,3 @@ pub enum Commands { command: Weblog, }, } - -#[derive(Subcommand)] -pub enum Account { - /// Get information about your account - GetInfo, - /// Get all addresses associated with your account - GetAddrs, - /// Get the name associated with your account - GetName, - /// Update the name associated with your account - SetName { - name: String, - }, - /// Get all sessions associated with your account - GetSessions, - /// Delete a session from your account - RemoveSession { - session_id: String, - }, - /// Get settings associated with your account - GetSettings, - /// Update settings associated with your account - SetSettings { - json_data: String, - }, -} - -#[derive(Subcommand)] -pub enum Address { - /// Get information about the availability of an address - IsAvailable, - /// Get the expiration date for an address - GetExpiry, - /// Get limited (public) information about an address (no auth required) - GetPublicInfo, - ///Get comprehensive information about an address - GetInfo, -} - -#[derive(Subcommand)] -pub enum DNS { - /// Get a list of all your DNS records - GetRecords, - /// Add a new DNS record - AddRecord { - json_data: String, - }, - /// Update an existing DNS record - UpdateRecord { - json_data: String, - }, - /// Delete a DNS record - DeleteRecord { - id: String, - }, -} - -#[derive(Subcommand)] -pub enum Email { - /// Get forwarding address(es) - GetForwards, - /// Set forwarding address(es) - SetForwards { - /// Addresses to forward emails to - json_data: String, - }, -} - -#[derive(Subcommand)] -pub enum Now { - /// Get the /now page for an address - Get, - /// Get all listed /now pages from now.garden - List, - /// Set the contents of the /now page for an address, remember to set the -l flag if you want your /now page listed - Set { - /// New content for the /now page - content: String, - /// List this /now page in now.garden - #[arg(short, long, default_value_t = false)] - listed: bool, - }, -} - -#[derive(Subcommand)] -pub enum Pastebin { - /// Get a specific paste for an omg.lol address - Get { - /// Name of the paste to get - name: String, - }, - /// Get all pastes for an omg.lol address - GetAll, - /// Get all public pastes for an omg.lol address - GetAllPublic, - /// Create/update a paste for an omg.lol address - Set { - /// Name of the paste to create (and the address used to retrieve it) - name: String, - /// Content of the paste - content: String, - }, - /// Detele a paste for an omg.lol address - Delete { - /// Name of the paste to delete - name: String, - }, -} - -#[derive(Subcommand)] -pub enum PURL { - /// Create a new PURL for an omg.lol address - Create { - /// Name of the PURL to create - name: String, - /// URL for the PURL to redirect to - url: String, - }, - /// Get a specific PURL for an omg.lol address - Get { - /// Name of the PURL to get - name: String, - }, - /// List all PURLs for an omg.lol address - List, - /// Delete a PURL for an omg.lol address - Delete { - /// Name of the PURL to delete - name: String, - }, -} - -#[derive(Subcommand)] -pub enum Status { - /// Get a single statuslog entry for an omg.lol address - Get { - /// ID of the statuslog entry to get - id: String, - }, - /// Get entire statuslog for an omg.lol address - GetAll, - /// Create a new statuslog entry for an omg.lol address - Create { - /// Emoji to use for the statuslog entry - emoji: String, - /// Content for the statuslog entry - content: String, - /// External URL to link to from the statuslog entry - external_url: String, // TODO: should this be optional? - }, - /// Create a new statuslog entry for an omg.lol address from a single string - EasyCreate { - /// Status to share - status: String, - }, - /// Update the content of an existing statuslog entry for an omg.lol address - Update { - /// ID of the statuslog entry to update - id: String, - /// New emoji to use for the statuslog entry - emoji: String, - /// New contrent for the statuslog entry - content: String, - // TODO: should there be an external url here? - }, - /// Get a statuslog bio - GetBio, - /// Update a statuslog bio - SetBio { - /// New content for statuslog bio - content: String, - }, - /// Get all statuslog entries for all addresses - GetAllHistorical, - /// Get the most recent statuslog entries across omg.lol - Timeline, -} - -#[derive(Subcommand)] -pub enum Theme { - /// List available omg.lol profile themes - List, - /// Get information about a specific theme - Info { - /// ID of the theme to get information for - id: String, - }, - /// Get a preview (HTML) of a theme - Preview { - /// ID of the theme to get a preview (HTML) of - id: String, - }, -} - -#[derive(Subcommand)] -pub enum Web { - /// Get web content and information for an omg.lol address - Get, - /// Update web content for an omg.lol address - Set { - /// New content for the web page - content: String, - /// Publish this page - #[arg(short, long, default_value_t = false)] - publish: bool, - }, - /// Set profile picture for an omg.lol address - SetPFP { - /// Path to image to upload as new profile picture - image: String, - // TODO: #[arg(value_parser = fn_that_takes_str_ref_and_returns_result_pathbuf)] - // Eg: #[arg(value_parser = |arg: &str| -> Result {Ok(Duration::from_secs(arg.parse()?))})] - }, -} - -#[derive(Subcommand)] -pub enum Weblog { - /// Get a specific weblog entry for an omg.lol address - Get { - /// ID of the weblog entry to get - id: String, - }, - /// Get the latest weblog entry for an omg.lol address - Latest, - /// Get all weblog entries for an omg.lol address - GetAll, - /// Create a new weblog entry for an omg.lol address - Create { - /// Content for the weblog entry - content: String, - }, - /// Delete a weblog entry for an omg.lol address - Delete { - /// ID of the weblog entry to delete - id: String, - }, - /// Get weblog configuration for an omg.lol address - GetConfig, - /// Update weblog configuration for an omg.lol address - SetConfig { - /// Content for the weblog configuration entry - content: String, - }, - /// Get the weblog template for an omg.lol address - GetTemplate, - /// Update the weblog template for an omg.lol address - SetTemplate { - /// Content for the weblog template entry - content: String, - }, -} \ No newline at end of file diff --git a/src/commands/account.rs b/src/commands/account.rs new file mode 100644 index 0000000..24ae6ce --- /dev/null +++ b/src/commands/account.rs @@ -0,0 +1,30 @@ +use clap::Subcommand; + +#[derive(Subcommand)] +pub enum Account { + /// Get information about your account + GetInfo, + /// Get all addresses associated with your account + GetAddresses, + /// Get the name associated with your account + GetName, + /// Update the name associated with your account + SetName { + /// Name to set for your account + name: String, + }, + /// Get all sessions associated with your account + GetSessions, + /// Delete a session from your account + RemoveSession { + /// ID of the session to remove + session_id: String, + }, + /// Get settings associated with your account + GetSettings, + /// Update settings associated with your account + SetSettings { + /// Temporary JSON data input + json_data: String, + }, +} diff --git a/src/commands/address.rs b/src/commands/address.rs new file mode 100644 index 0000000..a187e32 --- /dev/null +++ b/src/commands/address.rs @@ -0,0 +1,13 @@ +use clap::Subcommand; + +#[derive(Subcommand)] +pub enum Address { + /// Get information about the availability of an address + IsAvailable, + /// Get the expiration date for an address + GetExpiry, + /// Get limited (public) information about an address (no auth required) + GetPublicInfo, + ///Get comprehensive information about an address + GetInfo, +} diff --git a/src/commands/dns.rs b/src/commands/dns.rs new file mode 100644 index 0000000..15db619 --- /dev/null +++ b/src/commands/dns.rs @@ -0,0 +1,22 @@ +use clap::Subcommand; + +#[derive(Subcommand)] +pub enum Dns { + /// Get a list of all your DNS records + GetRecords, + /// Add a new DNS record + AddRecord { + /// Temporary JSON data input + json_data: String, + }, + /// Update an existing DNS record + UpdateRecord { + /// Temporary JSON data input + json_data: String, + }, + /// Delete a DNS record + DeleteRecord { + /// ID of the DNS record to delete + id: String, + }, +} diff --git a/src/commands/email.rs b/src/commands/email.rs new file mode 100644 index 0000000..526a121 --- /dev/null +++ b/src/commands/email.rs @@ -0,0 +1,12 @@ +use clap::Subcommand; + +#[derive(Subcommand)] +pub enum Email { + /// Get forwarding address(es) + GetForwards, + /// Set forwarding address(es) + SetForwards { + /// Addresses to forward emails to + json_data: String, + }, +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs new file mode 100644 index 0000000..2387efb --- /dev/null +++ b/src/commands/mod.rs @@ -0,0 +1,22 @@ +pub mod account; +pub use account::Account; +pub mod address; +pub use address::Address; +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; diff --git a/src/commands/now.rs b/src/commands/now.rs new file mode 100644 index 0000000..1e56fb7 --- /dev/null +++ b/src/commands/now.rs @@ -0,0 +1,17 @@ +use clap::Subcommand; + +#[derive(Subcommand)] +pub enum Now { + /// Get the /now page for an address + Get, + /// Get all listed /now pages from now.garden + List, + /// Set the contents of the /now page for an address, remember to set the -l flag if you want your /now page listed + Set { + /// New content for the /now page + content: String, + /// List this /now page in now.garden + #[arg(short, long, default_value_t = false)] + listed: bool, + }, +} diff --git a/src/commands/pastebin.rs b/src/commands/pastebin.rs new file mode 100644 index 0000000..9c31dee --- /dev/null +++ b/src/commands/pastebin.rs @@ -0,0 +1,26 @@ +use clap::Subcommand; + +#[derive(Subcommand)] +pub enum Pastebin { + /// Get a specific paste for an omg.lol address + Get { + /// Name of the paste to get + name: String, + }, + /// Get all pastes for an omg.lol address + GetAll, + /// Get all public pastes for an omg.lol address + GetAllPublic, + /// Create/update a paste for an omg.lol address + Set { + /// Name of the paste to create (and the address used to retrieve it) + name: String, + /// Content of the paste + content: String, + }, + /// Delete a paste for an omg.lol address + Delete { + /// Name of the paste to delete + name: String, + }, +} diff --git a/src/commands/purl.rs b/src/commands/purl.rs new file mode 100644 index 0000000..4f09145 --- /dev/null +++ b/src/commands/purl.rs @@ -0,0 +1,24 @@ +use clap::Subcommand; + +#[derive(Subcommand)] +pub enum Purl { + /// Create a new PURL for an omg.lol address + Create { + /// Name of the PURL to create + name: String, + /// URL for the PURL to redirect to + url: String, + }, + /// Get a specific PURL for an omg.lol address + Get { + /// Name of the PURL to get + name: String, + }, + /// List all PURLs for an omg.lol address + List, + /// Delete a PURL for an omg.lol address + Delete { + /// Name of the PURL to delete + name: String, + }, +} diff --git a/src/commands/status.rs b/src/commands/status.rs new file mode 100644 index 0000000..7839a78 --- /dev/null +++ b/src/commands/status.rs @@ -0,0 +1,47 @@ +use clap::Subcommand; + +#[derive(Subcommand)] +pub enum Status { + /// Get a single statuslog entry for an omg.lol address + Get { + /// ID of the statuslog entry to get + id: String, + }, + /// Get entire statuslog for an omg.lol address + GetAll, + /// Create a new statuslog entry for an omg.lol address + Create { + /// Emoji to use for the statuslog entry + emoji: String, + /// Content for the statuslog entry + content: String, + /// External URL to link to from the statuslog entry + external_url: String, // TODO: should this be optional? + }, + /// Create a new statuslog entry for an omg.lol address from a single string + EasyCreate { + /// Status to share + status: String, + }, + /// Update the content of an existing statuslog entry for an omg.lol address + Update { + /// ID of the statuslog entry to update + id: String, + /// New emoji to use for the statuslog entry + emoji: String, + /// New content for the statuslog entry + content: String, + // TODO: should there be an external url here? + }, + /// Get a statuslog bio + GetBio, + /// Update a statuslog bio + SetBio { + /// New content for statuslog bio + content: String, + }, + /// Get all statuslog entries for all addresses + GetAllHistorical, + /// Get the most recent statuslog entries across omg.lol + Timeline, +} diff --git a/src/commands/theme.rs b/src/commands/theme.rs new file mode 100644 index 0000000..4784626 --- /dev/null +++ b/src/commands/theme.rs @@ -0,0 +1,17 @@ +use clap::Subcommand; + +#[derive(Subcommand)] +pub enum Theme { + /// List available omg.lol profile themes + List, + /// Get information about a specific theme + Info { + /// ID of the theme to get information for + id: String, + }, + /// Get a preview (HTML) of a theme + Preview { + /// ID of the theme to get a preview (HTML) of + id: String, + }, +} diff --git a/src/commands/web.rs b/src/commands/web.rs new file mode 100644 index 0000000..bd35e09 --- /dev/null +++ b/src/commands/web.rs @@ -0,0 +1,22 @@ +use clap::Subcommand; + +#[derive(Subcommand)] +pub enum Web { + /// Get web content and information for an omg.lol address + Get, + /// Update web content for an omg.lol address + Set { + /// New content for the web page + content: String, + /// Publish this page + #[arg(short, long, default_value_t = false)] + publish: bool, + }, + /// Set profile picture for an omg.lol address + SetPFP { + /// Path to image to upload as new profile picture + image: String, + // TODO: #[arg(value_parser = fn_that_takes_str_ref_and_returns_result_pathbuf)] + // Eg: #[arg(value_parser = |arg: &str| -> Result {Ok(Duration::from_secs(arg.parse()?))})] + }, +} diff --git a/src/commands/weblog.rs b/src/commands/weblog.rs new file mode 100644 index 0000000..2d86610 --- /dev/null +++ b/src/commands/weblog.rs @@ -0,0 +1,38 @@ +use clap::Subcommand; + +#[derive(Subcommand)] +pub enum Weblog { + /// Get a specific weblog entry for an omg.lol address + Get { + /// ID of the weblog entry to get + id: String, + }, + /// Get the latest weblog entry for an omg.lol address + Latest, + /// Get all weblog entries for an omg.lol address + GetAll, + /// Create a new weblog entry for an omg.lol address + Create { + /// Content for the weblog entry + content: String, + }, + /// Delete a weblog entry for an omg.lol address + Delete { + /// ID of the weblog entry to delete + id: String, + }, + /// Get weblog configuration for an omg.lol address + GetConfig, + /// Update weblog configuration for an omg.lol address + SetConfig { + /// Content for the weblog configuration entry + content: String, + }, + /// Get the weblog template for an omg.lol address + GetTemplate, + /// Update the weblog template for an omg.lol address + SetTemplate { + /// Content for the weblog template entry + content: String, + }, +} diff --git a/src/main.rs b/src/main.rs index b097455..983aedf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ use std::fs::read_to_string; mod cli; use cli::{Cli, Commands}; +mod commands; #[derive(Default, Deserialize, Serialize)] struct Config { @@ -51,7 +52,7 @@ fn save_api_key(api_key: &str) -> std::io::Result<()> { .config_dir() .join("config.toml"); let _ = std::fs::create_dir_all( - &config_path + config_path .parent() .expect("Unable to get parent dir of config.toml"), );