diff options
-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" |