diff options
author | Lars Wirzenius <liw@liw.fi> | 2013-10-05 13:58:14 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2013-10-05 13:58:14 +0100 |
commit | f34f2a23b355f020759f714eb8fb567871de587c (patch) | |
tree | ac5c2bca815b4cb4c770ed4ccbb2775adf4e9784 | |
parent | 5b042d5679e1d61e432bd7812ac81d45a574dcda (diff) | |
download | clab-f34f2a23b355f020759f714eb8fb567871de587c.tar.gz |
Output each name/addr only once with mutt-query
-rwxr-xr-x | clab | 10 | ||||
-rw-r--r-- | clab.yarn | 23 |
2 files changed, 31 insertions, 2 deletions
@@ -147,12 +147,18 @@ class CommandLineAddressBook(cliapp.Application): self.output.write('No matches\n') sys.exit(1) self.output.write('clab found matches:\n') + + name_addr_pairs = set() for entry in entries: name = entry.get_single('name', '') emails = entry.get_subdict('email') for email in emails: - n = name.encode('utf-8') - self.output.write('%s\t%s\n' % (emails[email], n)) + name_addr_pairs.add((name, emails[email])) + + for name, addr in sorted(name_addr_pairs): + n = name.encode('utf-8') + a = addr.encode('utf-8') + self.output.write('%s\t%s\n' % (a, n)) CommandLineAddressBook().run() @@ -60,6 +60,15 @@ Put several records in one file. AND Bob is not found AND bob@example.com is not found +Sometimes the same person is in the database multiple times +(e.g., different records for home and work personas, where the +work persona is automatically generated from LDAP or something). +In this case, only find each person once. + + GIVEN another record for Alice (alice@example.com) + WHEN mutt-querying for example + THEN Alice is found only once + Implementation -------------- @@ -82,6 +91,12 @@ These implement the various steps. email: $MATCH_4 EOF + IMPLEMENTS GIVEN another record for (\S+) \((\S+)\) + cat << EOF >> "$DATADIR/db/foo.yaml" + - name: $MATCH_1 + email: $MATCH_2 + EOF + IMPLEMENTS WHEN listing all records ./clab --no-default-config --db "$DATADIR/db" list > "$DATADIR/output" @@ -106,5 +121,13 @@ These implement the various steps. set -x grep -F "$MATCH_1" "$DATADIR/output" + IMPLEMENTS THEN (.*) is found only once + n=$(grep -cF "$MATCH_1" "$DATADIR/output") + if [ "$n" != 1 ] + then + echo "$MATCH_1 was found $n times, expected 1" 1>&2 + exit 1 + fi + IMPLEMENTS THEN (.*) is not found ! grep -F "$MATCH_1" "$DATADIR/output" |