From 715130722f9e58936ff26be07eae055d9e18d1a5 Mon Sep 17 00:00:00 2001 From: Justin Date: Sat, 7 Oct 2023 00:04:15 -0400 Subject: [PATCH] add github/website commands to open links --- src/args.rs | 8 ++++++-- src/inbox.rs | 13 ++++--------- src/main.rs | 15 +++++++++++++-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/args.rs b/src/args.rs index c440f2b..272ff5c 100644 --- a/src/args.rs +++ b/src/args.rs @@ -18,7 +18,7 @@ pub enum Commands { #[arg(short = 'C', long)] copy: bool, }, - /// Open a specified email. + /// Open a specific email by providing the ID. Open { /// The ID of the email. #[arg()] @@ -42,5 +42,9 @@ pub enum Commands { copy: bool, }, /// Display the duration until the current inbox expires. - Expires + Expires, + /// Open the website that this program uses behind the scenes. + Website, + /// Open the GitHub repository for this application. + Github, } diff --git a/src/inbox.rs b/src/inbox.rs index 32eabb6..01e70d8 100644 --- a/src/inbox.rs +++ b/src/inbox.rs @@ -1,7 +1,7 @@ #[path = "cookies.rs"] mod cookies; -mod utils; mod date_time; +pub mod utils; pub mod email; use serde::Deserialize; @@ -11,7 +11,7 @@ use reqwest_cookie_store::CookieStoreMutex; use email::Email; use chrono::{Duration, DateTime, Utc}; -const DISPOSABLE_MAIL: &str = "https://www.disposablemail.com"; +pub const DISPOSABLE_MAIL: &str = "https://www.disposablemail.com"; /// A disposable email inbox. pub struct Inbox { @@ -94,7 +94,8 @@ impl Inbox { Ok(()) } - async fn get_exp_delta(&self) -> Result { + /// Determine how long it will be until this inbox expires. + pub async fn get_exp_delta(&self) -> Result { let response = self.client.get(format!("{}/index/zivot", DISPOSABLE_MAIL)) .headers(utils::headers(true)) .send() @@ -107,12 +108,6 @@ impl Inbox { Ok(li.end - li.now) } - pub async fn get_exp_delta_string(&self) -> Result { - let delta: Duration = self.get_exp_delta().await?; - let delta_str = utils::format_duration(delta); - Ok(delta_str) - } - /// Print cookies stored in Inbox. #[allow(dead_code)] pub fn print_cookies(&self) { diff --git a/src/main.rs b/src/main.rs index 407906a..f3ff12b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,10 +129,21 @@ async fn main() { }, args::Commands::Expires => { println!("Email address: {}", ai.email); - match inbox.get_exp_delta_string().await { - Ok(expires) => println!("Expires: {}", expires), + match inbox.get_exp_delta().await { + Ok(delta) => { + let expires = inbox::utils::format_duration(delta); + println!("Expires: {}", expires); + }, Err(err) => eprintln!("Failed to determine inbox expiration: {}", err) } + }, + args::Commands::Website => { + inbox::utils::open(inbox::DISPOSABLE_MAIL.to_string()); + println!("Opened DisposableMail website in browser."); + }, + args::Commands::Github => { + inbox::utils::open("https://github.com/ooojustin/clinbox".to_string()); + println!("Opened clinbox GitHub repository in browser."); } }