Derive debug for subcommands and accept &str

Instead of &Option<String>, as it will always be passed in
This commit is contained in:
Aadi Desai 2023-08-30 13:30:16 +01:00
parent 25ec3b53d7
commit e2c5de4a0a
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
14 changed files with 126 additions and 93 deletions

View file

@ -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<String>`
### 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

View file

@ -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"

View file

@ -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!(),
}
}
}

View file

@ -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,
GetPublicInfo {
/// Address to get availability of
address: String,
},
/// Get comprehensive information about an address
GetInfo,
GetInfo {
/// Address to get availability of
address: String,
},
}
impl Address {
pub fn process(&self, _address: &Option<String>) {
pub fn process(&self, api_key: &str) -> Result<AddressResponse, reqwest::Error> {
match self {
Address::IsAvailable => todo!(),
Address::GetExpiry => todo!(),

View file

@ -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<String>) {
pub fn process(&self, _address: &str) {
match self {
Dns::GetRecords => todo!(),
Dns::AddRecord { json_data: _ } => todo!(),

View file

@ -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<String>) {
pub fn process(&self, _address: &str) {
match self {
Email::GetForwards => todo!(),
Email::SetForwards { json_data: _ } => todo!(),

View file

@ -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<String>,
#[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<String>,
#[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<String>,
#[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<String>,
#[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<String>,
#[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<String>,
#[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<String>,
#[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<String>,
},
/// 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<String>,
#[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<String>,
#[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<String>,
#[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<String>) {
pub fn process(
&self,
_address: &str,
api_key: &str,
) -> Result<CommandResponse, reqwest::Error> {
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),
}

View file

@ -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<String>) {
pub fn process(&self, _address: &str) {
match self {
Now::Get => todo!(),
Now::List => todo!(),

View file

@ -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<String>) {
pub fn process(&self, _address: &str) {
match self {
Pastebin::Get { name: _ } => todo!(),
Pastebin::GetAll => todo!(),

View file

@ -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<String>) {
pub fn process(&self, _address: &str) {
match self {
Purl::Create { name: _, url: _ } => todo!(),
Purl::Get { name: _ } => todo!(),

View file

@ -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<String>) {
pub fn process(&self, _address: &str) {
match self {
Status::Get { id: _ } => todo!(),
Status::GetAll => todo!(),

View file

@ -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<String>) {
pub fn process(&self, _address: &str) {
match self {
Theme::List => todo!(),
Theme::Info { id: _ } => todo!(),

View file

@ -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<String>) {
pub fn process(&self, _address: &str) {
match self {
Web::Get => todo!(),
Web::Set { content: _, publish: _ } => todo!(),

View file

@ -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<String>) {
pub fn process(&self, _address: &str) {
match self {
Weblog::Get { id: _ } => todo!(),
Weblog::Latest => todo!(),