summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2013-03-23 14:15:23 +0000
committerLars Wirzenius <liw@liw.fi>2013-03-23 14:15:23 +0000
commit168c323a56bd0afd30d9fae11a4d262247bfdac6 (patch)
tree511d2c1c6c8ffa16abbbb40bab1e0b48b5ccea2b
parent46ba6cc020862d75b83ef4d757c3cb919f6a9d41 (diff)
downloadclab-168c323a56bd0afd30d9fae11a4d262247bfdac6.tar.gz
Add find cmd
-rwxr-xr-xclab16
1 files changed, 11 insertions, 5 deletions
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)