Exit with return code 1 when no results are found in atuin search command (#489)

* Exit with return code 1 when no results are found in `atuin search` command

* Remove random whitespace
This commit is contained in:
TymanWasTaken 2022-11-02 14:47:16 -06:00 committed by GitHub
parent f1f40a0d55
commit 6e3304b485
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -67,7 +67,7 @@ impl Cmd {
eprintln!("{}", item); eprintln!("{}", item);
} else { } else {
let list_mode = ListMode::from_flags(self.human, self.cmd_only); let list_mode = ListMode::from_flags(self.human, self.cmd_only);
run_non_interactive( let entries = run_non_interactive(
settings, settings,
list_mode, list_mode,
self.cwd, self.cwd,
@ -81,6 +81,9 @@ impl Cmd {
db, db,
) )
.await?; .await?;
if entries == 0 {
std::process::exit(1)
}
}; };
Ok(()) Ok(())
} }
@ -101,7 +104,7 @@ async fn run_non_interactive(
limit: Option<i64>, limit: Option<i64>,
query: &[String], query: &[String],
db: &mut impl Database, db: &mut impl Database,
) -> Result<()> { ) -> Result<usize> {
let dir = if cwd.as_deref() == Some(".") { let dir = if cwd.as_deref() == Some(".") {
let current = std::env::current_dir()?; let current = std::env::current_dir()?;
let current = current.as_os_str(); let current = current.as_os_str();
@ -177,5 +180,5 @@ async fn run_non_interactive(
.collect(); .collect();
super::history::print_list(&results, list_mode); super::history::print_list(&results, list_mode);
Ok(()) Ok(results.len())
} }