From cc72d58994924bc58d610ce9ef303e3b33fcf847 Mon Sep 17 00:00:00 2001 From: b1ek Date: Tue, 22 Oct 2024 14:43:19 +1000 Subject: [PATCH] add an option to clear session --- src/main.rs | 8 ++++++++ src/session.rs | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/main.rs b/src/main.rs index 3a3ecb6..ffdf700 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,8 @@ pub const GRAY: &str = "\x1b[30m"; struct Args { #[arg(long, default_value = "false", required = false, help = "If you want to agree to the DuckDuckGo TOS")] pub agree_tos: bool, + #[arg(long, short, default_value = "false", required = false, help = "Clear current session")] + pub clear: bool, #[arg()] pub query: Vec, } @@ -43,6 +45,12 @@ async fn main() { let args = Args::parse(); let query = args.query.join(" ").trim().to_string(); + if args.clear { + Session::clear(); + println!("Cleared session"); + exit(0); + } + { let session = Session::create_or_restore(""); if session.is_restored() { diff --git a/src/session.rs b/src/session.rs index 91c89a2..b2f8ef9 100644 --- a/src/session.rs +++ b/src/session.rs @@ -118,6 +118,13 @@ impl Session { self.ttl < Local::now() } + pub fn clear() { + let session = Session::create_or_restore(""); + if session.is_restored() { + session.destroy().unwrap(); + } + } + pub fn is_restored(&self) -> bool { self.restored }