summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-03-12 11:47:32 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-03-12 11:47:32 -0400
commitea4d9cb99ba2390344c36a88c4d17c8769912867 (patch)
tree2f291aa218bac9c827587a87797dcef26dc07027 /cmd2.py
parent1fe2d681507dcb226f0950ae089315dc2398ab44 (diff)
downloadcmd2-git-ea4d9cb99ba2390344c36a88c4d17c8769912867.tar.gz
Fixed a bug where an exception would occur if the list command was run with an empty history.
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/cmd2.py b/cmd2.py
index 01270d12..564c1d3f 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1581,6 +1581,15 @@ class History(list):
return result
def search(self, target):
+ """ Search the history for a particular term.
+
+ :param target: str - term to search for
+ :return: List[str] - list of matches
+ """
+ # If there is no history yet, don't try to search through a non-existent list, just return an empty list
+ if len(self) < 1:
+ return []
+
target = target.strip()
if target[0] == target[-1] == '/' and len(target) > 1:
target = target[1:-1]
@@ -1858,4 +1867,5 @@ class CmdResult(namedtuple('CmdResult', ['out', 'err', 'war'])):
if __name__ == '__main__':
# If run as the main application, simply start a bare-bones cmd2 application with only built-in functionality.
app = Cmd()
+ app.debug = True
app.cmdloop()