summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-20 06:04:55 +0000
committerLars Wirzenius <liw@liw.fi>2021-04-20 06:04:55 +0000
commitc03d919a68676eb321d9e4505bfeb5829884e924 (patch)
treec01fdb27b2960188ec89d446fa03de3ce4d75093
parent09222b55e69b409b3408c325b47b7936ca0ac08d (diff)
parenteccfd79e12187468fc491078c5d32f531c686f01 (diff)
downloadclab-c03d919a68676eb321d9e4505bfeb5829884e924.tar.gz
Merge branch 'mutt-query' into 'main'
fix: output of mutt-query Closes #1 See merge request larswirzenius/clab!1
-rw-r--r--clab.md8
-rw-r--r--src/main.rs11
2 files changed, 13 insertions, 6 deletions
diff --git a/clab.md b/clab.md
index 9b2bef4..f471726 100644
--- a/clab.md
+++ b/clab.md
@@ -13,6 +13,9 @@ then command is successful
when I run clab search Alice
then command is successful
then stdout is exactly ""
+
+when I try to run clab mutt-query Alice
+then command fails
~~~
# Alice and Bob
@@ -43,10 +46,7 @@ then stdout doesn't contain "Bob"
when I run clab mutt-query Alice
then command is successful
-then stdout contains "Alice Atherthon"
-then stdout contains "alice@example.com"
-then stdout doesn't contain "Bob"
-then stdout doesn't contain "bob@example.com"
+then stdout is exactly "clab found matches:\nalice@example.com\tAlice Atherthon\n"
~~~
~~~{#address-book.yaml .file .yaml}
diff --git a/src/main.rs b/src/main.rs
index 08fc655..b8645d5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -176,9 +176,16 @@ struct MuttCommand {
impl MuttCommand {
fn run(&self, _opt: &Opt, book: &AddressBook) {
- for e in book.iter().filter(|e| self.is_match(e)) {
+ let matches: Vec<Entry> = book.iter().filter(|e| self.is_match(e)).cloned().collect();
+ if matches.is_empty() {
+ println!("clab found no matches");
+ std::process::exit(1);
+ }
+
+ println!("clab found matches:");
+ for e in matches {
for email in e.emails() {
- println!("{}\t{}", e.name, email);
+ println!("{}\t{}", email, e.name);
}
}
}