summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-02 17:45:12 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-02 17:45:12 -0400
commitb0c3fa4dd7d762fb812a9cf74e6879dbfba04a50 (patch)
tree7324bef4db334308b257388f758e259b85d09da7 /cmd2.py
parent482e9ce1f21677667eca52326d966a594ef6cc1a (diff)
downloadcmd2-git-b0c3fa4dd7d762fb812a9cf74e6879dbfba04a50.tar.gz
Fixed bugs, removed dead code, and added unit tests
Fixed a bug where CmdResult named tuple Truthiness wasn't working in Python 2 Removed unused cmd2.History.search() method. Added unit tests for: - History class - cast() function - CmdResult namedtuple
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py22
1 files changed, 4 insertions, 18 deletions
diff --git a/cmd2.py b/cmd2.py
index c17c8d07..56df1750 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1967,24 +1967,6 @@ class History(list):
result = None
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]
- else:
- target = re.escape(target)
- pattern = re.compile(target, re.IGNORECASE)
- return [s for s in self if pattern.search(s)]
-
spanpattern = re.compile(r'^\s*(?P<start>-?\d+)?\s*(?P<separator>:|(\.{2,}))?\s*(?P<end>-?\d+)?\s*$')
def span(self, raw):
@@ -2287,6 +2269,10 @@ class CmdResult(namedtuple_with_two_defaults('CmdResult', ['out', 'err', 'war'])
"""If err is an empty string, treat the result as a success; otherwise treat it as a failure."""
return not self.err
+ def __nonzero__(self):
+ """Python 2 uses this method for determining Truthiness"""
+ return self.__bool__()
+
if __name__ == '__main__':
# If run as the main application, simply start a bare-bones cmd2 application with only built-in functionality.