Move commands into separate submodules

Submodules are located under commands module
This commit is contained in:
Aadi Desai 2023-04-25 00:52:06 +01:00
parent aba80284d3
commit 6540c41f1f
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
14 changed files with 302 additions and 261 deletions

View file

@ -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<String>,
@ -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<String>,
#[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<String>,
#[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<String>,
@ -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<Duration, ParseIntError> {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,
},
}

30
src/commands/account.rs Normal file
View file

@ -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,
},
}

13
src/commands/address.rs Normal file
View file

@ -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,
}

22
src/commands/dns.rs Normal file
View file

@ -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,
},
}

12
src/commands/email.rs Normal file
View file

@ -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,
},
}

22
src/commands/mod.rs Normal file
View file

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

17
src/commands/now.rs Normal file
View file

@ -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,
},
}

26
src/commands/pastebin.rs Normal file
View file

@ -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,
},
}

24
src/commands/purl.rs Normal file
View file

@ -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,
},
}

47
src/commands/status.rs Normal file
View file

@ -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,
}

17
src/commands/theme.rs Normal file
View file

@ -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,
},
}

22
src/commands/web.rs Normal file
View file

@ -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<Duration, ParseIntError> {Ok(Duration::from_secs(arg.parse()?))})]
},
}

38
src/commands/weblog.rs Normal file
View file

@ -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,
},
}

View file

@ -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"),
);