Switch to external api crate

And add submodule link to repository
This commit is contained in:
Aadi Desai 2023-05-08 23:07:07 +01:00
parent cfc4abbab4
commit 4336eaa5eb
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
19 changed files with 25 additions and 565 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "omg-api"]
path = omg-api
url = git@github.com:supleed2/omg-api.git

View file

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

16
Cargo.lock generated
View file

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

View file

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

1
omg-api Submodule

@ -0,0 +1 @@
Subproject commit 40ebdf777d75bedc8b73bf3f2ddc97b173f7a328

View file

@ -1,5 +1,5 @@
use crate::commands::Commands;
use clap::Parser;
use omg_api::Commands;
#[derive(Parser)]
pub struct Cli {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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