diff options
Diffstat (limited to 'clab')
-rwxr-xr-x | clab | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -71,11 +71,12 @@ class AddressBook(object): entry = Entry(parsed_yaml) self.entries.append(entry) - def find(self, pattern): - return [e for e in self.entries if self.matches(e, pattern)] + def find(self, patterns): + return [e for e in self.entries if self.matches(e, patterns)] - def matches(self, entry, pattern): - return pattern.lower() in entry.as_yaml().lower() + def matches(self, entry, patterns): + s = entry.as_yaml().lower() + return any(p.lower() in s for p in patterns) class CommandLineAddressBook(cliapp.Application): @@ -97,13 +98,18 @@ class CommandLineAddressBook(cliapp.Application): for entry in book.entries: self.output.write(entry.as_yaml() + '\n') + def cmd_find(self, args): + book = self.load_address_book() + for entry in book.find(args): + self.output.write(entry.as_yaml() + '\n') + def cmd_mutt_query(self, args): if len(args) != 1: raise cliapp.AppException( 'mutt-query requires exactly one argument') book = self.load_address_book() - entries = book.find(args[0]) + entries = book.find(args) if not entries: self.output.write('No matches\n') sys.exit(1) |