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 }