add an option to clear session

This commit is contained in:
b1ek 2024-10-22 14:43:19 +10:00
parent 85bc4265cf
commit cc72d58994
Signed by: blek
GPG Key ID: A622C22C9BC616B2
2 changed files with 15 additions and 0 deletions

View File

@ -26,6 +26,8 @@ pub const GRAY: &str = "\x1b[30m";
struct Args { struct Args {
#[arg(long, default_value = "false", required = false, help = "If you want to agree to the DuckDuckGo TOS")] #[arg(long, default_value = "false", required = false, help = "If you want to agree to the DuckDuckGo TOS")]
pub agree_tos: bool, pub agree_tos: bool,
#[arg(long, short, default_value = "false", required = false, help = "Clear current session")]
pub clear: bool,
#[arg()] #[arg()]
pub query: Vec<String>, pub query: Vec<String>,
} }
@ -43,6 +45,12 @@ async fn main() {
let args = Args::parse(); let args = Args::parse();
let query = args.query.join(" ").trim().to_string(); let query = args.query.join(" ").trim().to_string();
if args.clear {
Session::clear();
println!("Cleared session");
exit(0);
}
{ {
let session = Session::create_or_restore(""); let session = Session::create_or_restore("");
if session.is_restored() { if session.is_restored() {

View File

@ -118,6 +118,13 @@ impl Session {
self.ttl < Local::now() 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 { pub fn is_restored(&self) -> bool {
self.restored self.restored
} }