diff options
| author | Conrad Ludgate <conrad.ludgate@truelayer.com> | 2022-04-21 10:12:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-21 09:12:56 +0000 |
| commit | d57f549855caf8ab90b5ea0ae7cc9445f3abedfc (patch) | |
| tree | 0818ff405a3b697a0ca981d215ceb4dbb30cd15a /src/command/search.rs | |
| parent | Fix SQL cache query (#318) (diff) | |
| download | atuin-d57f549855caf8ab90b5ea0ae7cc9445f3abedfc.zip | |
refactor commands for better separation (#313)
* refactor commands for better separation
* fmt
Diffstat (limited to '')
| -rw-r--r-- | src/command/client/search.rs (renamed from src/command/search.rs) | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/src/command/search.rs b/src/command/client/search.rs index a28b1542..a1dc5aa9 100644 --- a/src/command/search.rs +++ b/src/command/client/search.rs @@ -1,7 +1,7 @@ use chrono::Utc; +use clap::Parser; use eyre::Result; use std::{io::stdout, ops::Sub, time::Duration}; - use termion::{event::Key, input::MouseTerminal, raw::IntoRawMode, screen::AlternateScreen}; use tui::{ backend::{Backend, TermionBackend}, @@ -19,10 +19,75 @@ use atuin_client::{ settings::{SearchMode, Settings}, }; -use crate::command::event::{Event, Events}; +use super::event::{Event, Events}; const VERSION: &str = env!("CARGO_PKG_VERSION"); +#[derive(Parser)] +pub struct Cmd { + /// Filter search result by directory + #[clap(long, short)] + cwd: Option<String>, + + /// Exclude directory from results + #[clap(long = "exclude-cwd")] + exclude_cwd: Option<String>, + + /// Filter search result by exit code + #[clap(long, short)] + exit: Option<i64>, + + /// Exclude results with this exit code + #[clap(long = "exclude-exit")] + exclude_exit: Option<i64>, + + /// Only include results added before this date + #[clap(long, short)] + before: Option<String>, + + /// Only include results after this date + #[clap(long)] + after: Option<String>, + + /// Open interactive search UI + #[clap(long, short)] + interactive: bool, + + /// Use human-readable formatting for time + #[clap(long)] + human: bool, + + query: Vec<String>, + + /// Show only the text of the command + #[clap(long)] + cmd_only: bool, +} + +impl Cmd { + pub async fn run( + self, + db: &mut (impl Database + Send + Sync), + settings: &Settings, + ) -> Result<()> { + run( + settings, + self.cwd, + self.exit, + self.interactive, + self.human, + self.exclude_exit, + self.exclude_cwd, + self.before, + self.after, + self.cmd_only, + &self.query, + db, + ) + .await + } +} + struct State { input: String, |
