def _cmd_list(self, options, *args): """Print a list""" if args: entries = self.parse_indices(*args) else: entries = self.phonebook entries = phonebook.sort_entries_by_field(entries, options.sortby[0], options.sortby[1], options.ignore_case) self.print_short_list(entries)
def _cmd_show(self, options, *args): """Show a single entry""" if args: entries = self.parse_indices(*args) else: entries = self.phonebook entries = phonebook.sort_entries_by_field(entries, options.sortby[0], options.sortby[1], options.ignore_case) self.print_long_list(entries)
def _cmd_table(self, options, *args): """Print a table""" if args: entries = self.parse_indices(*args) else: entries = self.phonebook entries = phonebook.sort_entries_by_field(entries, options.sortby[0], options.sortby[1], options.ignore_case) self.print_table(entries, options.output)
def _cmd_search(self, options, *args): """Search the phone book for `pattern`""" found = [] for pattern in args: entries = self.phonebook.search(pattern, options.ignore_case, options.regexp, options.fields) # add all entries which aren't already in found. This avoids # printing entries twice, which are matched by more than one # pattern new = filter(lambda entry: entry not in found, entries) found += new entries = phonebook.sort_entries_by_field(found, options.sortby[0], options.sortby[1], options.ignore_case) self.print_table(found, options.output)