From dcd77749dd1fdf6b0c8183bfbdf4f97bf238ebe4 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Mon, 20 Mar 2023 09:26:54 +0000 Subject: Add history deletion (#791) * Drop events. I'd still like to do them, but differently * Start adding delete api stuff * Set mailmap * Delete delete delete * Fix tests * Make clippy happy --- src/command/client/history.rs | 2 +- src/command/client/search.rs | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/command/client/history.rs b/src/command/client/history.rs index 8735123e..c8f6b535 100644 --- a/src/command/client/history.rs +++ b/src/command/client/history.rs @@ -184,7 +184,7 @@ impl Cmd { // store whatever is ran, than to throw an error to the terminal let cwd = utils::get_current_dir(); - let h = History::new(chrono::Utc::now(), command, cwd, -1, -1, None, None); + let h = History::new(chrono::Utc::now(), command, cwd, -1, -1, None, None, None); // print the ID // we use this as the key for calling end diff --git a/src/command/client/search.rs b/src/command/client/search.rs index 0a728cc5..dd6fcb32 100644 --- a/src/command/client/search.rs +++ b/src/command/client/search.rs @@ -76,6 +76,10 @@ pub struct Cmd { #[arg(long)] cmd_only: bool, + // Delete anything matching this query. Will not print out the match + #[arg(long)] + delete: bool, + /// Available variables: {command}, {directory}, {duration}, {user}, {host} and {time}. /// Example: --format "{time} - [{duration}] - {directory}$\t{command}" #[arg(long, short)] @@ -100,12 +104,10 @@ impl Cmd { let list_mode = ListMode::from_flags(self.human, self.cmd_only); let entries = run_non_interactive( settings, - list_mode, self.cwd, self.exit, self.exclude_exit, self.exclude_cwd, - self.format, self.before, self.after, self.limit, @@ -113,9 +115,22 @@ impl Cmd { db, ) .await?; - if entries == 0 { + + if entries.is_empty() { std::process::exit(1) } + + // if we aren't deleting, print it all + if self.delete { + // delete it + // it only took me _years_ to add this + // sorry + for entry in entries { + db.delete(entry).await?; + } + } else { + super::history::print_list(&entries, list_mode, self.format.as_deref()); + } }; Ok(()) } @@ -126,18 +141,16 @@ impl Cmd { #[allow(clippy::too_many_arguments)] async fn run_non_interactive( settings: &Settings, - list_mode: ListMode, cwd: Option, exit: Option, exclude_exit: Option, exclude_cwd: Option, - format: Option, before: Option, after: Option, limit: Option, query: &[String], db: &mut impl Database, -) -> Result { +) -> Result> { let dir = if cwd.as_deref() == Some(".") { Some(utils::get_current_dir()) } else { @@ -202,6 +215,5 @@ async fn run_non_interactive( .map(std::borrow::ToOwned::to_owned) .collect(); - super::history::print_list(&results, list_mode, format.as_deref()); - Ok(results.len()) + Ok(results) } -- cgit v1.3.1