mirror of
https://github.com/supleed2/omg-rs.git
synced 2024-12-22 13:45:51 +00:00
Move commands from cli to commands submodule
This commit is contained in:
parent
9910c3f8bf
commit
cfc4abbab4
116
src/cli.rs
116
src/cli.rs
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::*;
|
use crate::commands::Commands;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::Parser;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
|
@ -13,115 +13,3 @@ pub struct Cli {
|
||||||
#[arg(short, long, action = clap::ArgAction::Count)]
|
#[arg(short, long, action = clap::ArgAction::Count)]
|
||||||
pub verbose: u8,
|
pub verbose: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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: Option<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<String>,
|
|
||||||
#[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<String>,
|
|
||||||
#[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<String>,
|
|
||||||
#[clap(subcommand)]
|
|
||||||
command: Email,
|
|
||||||
},
|
|
||||||
/// Manage your /now page
|
|
||||||
Now {
|
|
||||||
/// omg.lol address to interact with
|
|
||||||
#[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
|
|
||||||
#[clap(short, long, global = true)]
|
|
||||||
address: Option<String>,
|
|
||||||
#[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<String>,
|
|
||||||
#[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<String>,
|
|
||||||
#[clap(subcommand)]
|
|
||||||
command: Status,
|
|
||||||
},
|
|
||||||
/// Manage omg.lol profile themes
|
|
||||||
Theme {
|
|
||||||
/// omg.lol address to interact with
|
|
||||||
#[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
|
|
||||||
#[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
|
|
||||||
#[clap(short, long, global = true)]
|
|
||||||
address: Option<String>,
|
|
||||||
#[clap(subcommand)]
|
|
||||||
command: Weblog,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
|
@ -28,3 +28,18 @@ pub enum Account {
|
||||||
json_data: String,
|
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!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -11,3 +11,14 @@ pub enum Address {
|
||||||
///Get comprehensive information about an address
|
///Get comprehensive information about an address
|
||||||
GetInfo,
|
GetInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Address {
|
||||||
|
pub fn process(&self) {
|
||||||
|
match self {
|
||||||
|
Address::IsAvailable => todo!(),
|
||||||
|
Address::GetExpiry => todo!(),
|
||||||
|
Address::GetPublicInfo => todo!(),
|
||||||
|
Address::GetInfo => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,3 +20,14 @@ pub enum Dns {
|
||||||
id: String,
|
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!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,3 +10,12 @@ pub enum Email {
|
||||||
json_data: String,
|
json_data: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Email {
|
||||||
|
pub fn process(&self) {
|
||||||
|
match self {
|
||||||
|
Email::GetForwards => todo!(),
|
||||||
|
Email::SetForwards { json_data } => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use clap::Subcommand;
|
||||||
|
|
||||||
pub mod account;
|
pub mod account;
|
||||||
pub use account::Account;
|
pub use account::Account;
|
||||||
pub mod address;
|
pub mod address;
|
||||||
|
@ -20,3 +22,138 @@ pub mod web;
|
||||||
pub use web::Web;
|
pub use web::Web;
|
||||||
pub mod weblog;
|
pub mod weblog;
|
||||||
pub use weblog::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<String>,
|
||||||
|
#[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<String>,
|
||||||
|
#[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<String>,
|
||||||
|
#[clap(subcommand)]
|
||||||
|
command: Email,
|
||||||
|
},
|
||||||
|
/// Manage your /now page
|
||||||
|
Now {
|
||||||
|
/// omg.lol address to interact with
|
||||||
|
#[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
|
||||||
|
#[clap(short, long, global = true)]
|
||||||
|
address: Option<String>,
|
||||||
|
#[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<String>,
|
||||||
|
#[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<String>,
|
||||||
|
#[clap(subcommand)]
|
||||||
|
command: Status,
|
||||||
|
},
|
||||||
|
/// Manage omg.lol profile themes
|
||||||
|
Theme {
|
||||||
|
/// omg.lol address to interact with
|
||||||
|
#[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
|
||||||
|
#[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
|
||||||
|
#[clap(short, long, global = true)]
|
||||||
|
address: Option<String>,
|
||||||
|
#[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!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -15,3 +15,13 @@ pub enum Now {
|
||||||
listed: bool,
|
listed: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Now {
|
||||||
|
pub fn process(&self) {
|
||||||
|
match self {
|
||||||
|
Now::Get => todo!(),
|
||||||
|
Now::List => todo!(),
|
||||||
|
Now::Set { content, listed } => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -24,3 +24,15 @@ pub enum Pastebin {
|
||||||
name: String,
|
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!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -22,3 +22,14 @@ pub enum Purl {
|
||||||
name: String,
|
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!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -45,3 +45,19 @@ pub enum Status {
|
||||||
/// Get the most recent statuslog entries across omg.lol
|
/// Get the most recent statuslog entries across omg.lol
|
||||||
Timeline,
|
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!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -15,3 +15,13 @@ pub enum Theme {
|
||||||
id: String,
|
id: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Theme {
|
||||||
|
pub fn process(&self) {
|
||||||
|
match self {
|
||||||
|
Theme::List => todo!(),
|
||||||
|
Theme::Info { id } => todo!(),
|
||||||
|
Theme::Preview { id } => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,3 +20,13 @@ pub enum Web {
|
||||||
// Eg: #[arg(value_parser = |arg: &str| -> Result<Duration, ParseIntError> {Ok(Duration::from_secs(arg.parse()?))})]
|
// Eg: #[arg(value_parser = |arg: &str| -> Result<Duration, ParseIntError> {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!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -36,3 +36,19 @@ pub enum Weblog {
|
||||||
content: String,
|
content: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Weblog {
|
||||||
|
pub fn process(&self, _address: &Option<String>) {
|
||||||
|
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!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
use cli::{Cli, Commands};
|
use cli::Cli;
|
||||||
mod commands;
|
mod commands;
|
||||||
|
|
||||||
#[derive(Default, Deserialize, Serialize)]
|
#[derive(Default, Deserialize, Serialize)]
|
||||||
|
@ -17,7 +17,7 @@ struct Config {
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
if let Some(Commands::Auth { api_key }) = cli.command {
|
if let Some(commands::Commands::Auth { api_key }) = cli.command {
|
||||||
match save_api_key(&api_key) {
|
match save_api_key(&api_key) {
|
||||||
Ok(_) => std::process::exit(0),
|
Ok(_) => std::process::exit(0),
|
||||||
Err(_) => std::process::exit(1),
|
Err(_) => std::process::exit(1),
|
||||||
|
|
Loading…
Reference in a new issue