diff options
| author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-03-12 11:47:32 -0400 |
|---|---|---|
| committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-03-12 11:47:32 -0400 |
| commit | ea4d9cb99ba2390344c36a88c4d17c8769912867 (patch) | |
| tree | 2f291aa218bac9c827587a87797dcef26dc07027 /cmd2.py | |
| parent | 1fe2d681507dcb226f0950ae089315dc2398ab44 (diff) | |
| download | cmd2-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-x | cmd2.py | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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() |
