From 8ced5469b18f65f082d0669ccfb23a5dbada6c8b Mon Sep 17 00:00:00 2001 From: catherine Date: Thu, 28 Jan 2010 07:55:34 -0500 Subject: throw error from .span' --- cmd2.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'cmd2.py') diff --git a/cmd2.py b/cmd2.py index 6ad34ca..d7bf463 100755 --- a/cmd2.py +++ b/cmd2.py @@ -944,16 +944,16 @@ class Cmd(cmd.Cmd): def do_list(self, arg): """list [arg]: lists last command issued - no arg -> list absolute last + no arg -> list most recent command arg is integer -> list one history item, by index - - arg, arg - (integer) -> list up to or after #arg + a..b, a:b, a:, ..b -> list spans from a (or start) to b (or end) arg is string -> list last command matching string search arg is /enclosed in forward-slashes/ -> regular expression search """ #TODO: totally failing to recognize args try: #self.stdout.write(self.last_matching(arg).pr()) - for hi in self.history.get(arg or -1): + for hi in self.history.span(arg or '-1'): self.poutput(hi.pr()) except: pass @@ -1108,7 +1108,7 @@ class HistoryItem(str): self.lowercase = self.lower() self.idx = None def pr(self): - return listformat % (self.idx, str(self)) + return self.listformat % (self.idx, str(self)) class History(list): '''A list of HistoryItems that knows how to respond to user requests. @@ -1128,6 +1128,8 @@ class History(list): >>> h.span('-2..-3') ['third', 'second'] ''' + def find(self, target): + def zero_based_index(self, onebased): result = onebased if result > 0: @@ -1142,6 +1144,8 @@ class History(list): spanpattern = re.compile(r'^\s*(?P\-?\d+)?\s*(?P:|(\.{2,}))?\s*(?P\-?\d+)?\s*$') def span(self, raw): results = self.spanpattern.search(raw) + if not results: + raise IndexError if not results.group('separator'): return [self[self.to_index(results.group('start'))]] start = self.to_index(results.group('start')) -- cgit v1.2.1