From 168c323a56bd0afd30d9fae11a4d262247bfdac6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 23 Mar 2013 14:15:23 +0000 Subject: Add find cmd --- clab | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'clab') diff --git a/clab b/clab index 6bb6f96..c43f91d 100755 --- a/clab +++ b/clab @@ -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) -- cgit v1.2.1