diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..33c6513 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "omg-api"] + path = omg-api + url = git@github.com:supleed2/omg-api.git diff --git a/CHANGELOG.md b/CHANGELOG.md index 80b7f90..370b486 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Switch to external version of commands crate, [omg-api](https://github.com/supleed2/omg-api). + ### Deprecated ### Removed diff --git a/Cargo.lock b/Cargo.lock index 153dda5..f4f81de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,9 +101,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.2.2" +version = "4.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b802d85aaf3a1cdb02b224ba472ebdea62014fccfcb269b95a4d76443b5ee5a" +checksum = "34d21f9bf1b425d2968943631ec91202fe5e837264063503708b83013f8fc938" dependencies = [ "clap_builder", "clap_derive", @@ -112,9 +112,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.2.2" +version = "4.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14a1a858f532119338887a4b8e1af9c60de8249cd7bafd68036a489e261e37b6" +checksum = "914c8c79fb560f238ef6429439a30023c862f7a28e688c58f7203f12b29970bd" dependencies = [ "anstream", "anstyle", @@ -587,11 +587,19 @@ dependencies = [ "anyhow", "clap", "directories", + "omg-api", "reqwest", "serde", "toml", ] +[[package]] +name = "omg-api" +version = "0.1.0" +dependencies = [ + "clap", +] + [[package]] name = "once_cell" version = "1.17.1" diff --git a/Cargo.toml b/Cargo.toml index bd46679..9905c78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,10 @@ repository = "https://github.com/supleed2/omg-rs" anyhow = "1.0.70" clap = { version = "4.2.2", features = ["derive"] } directories = "5.0.0" +omg-api = "0.1.0" reqwest = { version = "0.11.16", features = ["blocking", "json"] } serde = { version = "1.0.160", features = ["derive"] } toml = "0.7.3" + +[patch.crates-io] +omg-api = { path = "omg-api" } diff --git a/omg-api b/omg-api new file mode 160000 index 0000000..40ebdf7 --- /dev/null +++ b/omg-api @@ -0,0 +1 @@ +Subproject commit 40ebdf777d75bedc8b73bf3f2ddc97b173f7a328 diff --git a/src/cli.rs b/src/cli.rs index 91373db..96026a1 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,5 +1,5 @@ -use crate::commands::Commands; use clap::Parser; +use omg_api::Commands; #[derive(Parser)] pub struct Cli { diff --git a/src/commands/account.rs b/src/commands/account.rs deleted file mode 100644 index c98262f..0000000 --- a/src/commands/account.rs +++ /dev/null @@ -1,45 +0,0 @@ -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, - }, -} - -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 deleted file mode 100644 index 13e0f0d..0000000 --- a/src/commands/address.rs +++ /dev/null @@ -1,24 +0,0 @@ -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, -} - -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 deleted file mode 100644 index 553547f..0000000 --- a/src/commands/dns.rs +++ /dev/null @@ -1,33 +0,0 @@ -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, - }, -} - -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 deleted file mode 100644 index 328ecbb..0000000 --- a/src/commands/email.rs +++ /dev/null @@ -1,21 +0,0 @@ -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, - }, -} - -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 deleted file mode 100644 index b62496c..0000000 --- a/src/commands/mod.rs +++ /dev/null @@ -1,159 +0,0 @@ -use clap::Subcommand; - -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; - -// 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 deleted file mode 100644 index 1fcaf04..0000000 --- a/src/commands/now.rs +++ /dev/null @@ -1,27 +0,0 @@ -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, - }, -} - -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 deleted file mode 100644 index 95d2710..0000000 --- a/src/commands/pastebin.rs +++ /dev/null @@ -1,38 +0,0 @@ -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, - }, -} - -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 deleted file mode 100644 index e1d9a3b..0000000 --- a/src/commands/purl.rs +++ /dev/null @@ -1,35 +0,0 @@ -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, - }, -} - -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 deleted file mode 100644 index 3b9e1ef..0000000 --- a/src/commands/status.rs +++ /dev/null @@ -1,63 +0,0 @@ -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, -} - -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 deleted file mode 100644 index 49e3ef2..0000000 --- a/src/commands/theme.rs +++ /dev/null @@ -1,27 +0,0 @@ -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, - }, -} - -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 deleted file mode 100644 index 15db3bf..0000000 --- a/src/commands/web.rs +++ /dev/null @@ -1,32 +0,0 @@ -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()?))})] - }, -} - -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 deleted file mode 100644 index 60875a8..0000000 --- a/src/commands/weblog.rs +++ /dev/null @@ -1,54 +0,0 @@ -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, - }, -} - -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 22356fc..04555cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,12 @@ use anyhow::Context; use clap::Parser; use directories::ProjectDirs; +use omg_api::Commands; use serde::{Deserialize, Serialize}; use std::fs::read_to_string; mod cli; use cli::Cli; -mod commands; #[derive(Default, Deserialize, Serialize)] struct Config { @@ -17,7 +17,7 @@ struct Config { fn main() -> anyhow::Result<()> { let cli = Cli::parse(); - if let Some(commands::Commands::Auth { api_key }) = cli.command { + if let Some(Commands::Auth { api_key }) = cli.command { match save_api_key(&api_key) { Ok(_) => std::process::exit(0), Err(_) => std::process::exit(1),