add an option to clear session
This commit is contained in:
parent
85bc4265cf
commit
cc72d58994
|
@ -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<String>,
|
||||
}
|
||||
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue