Skip to content

Commit eb3d295

Browse files
authored
Merge pull request #117 from python-cmd2/history_exception
Bug fix for history exception
2 parents ccef0b4 + 3fa8f11 commit eb3d295

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

cmd2.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,8 +1610,11 @@ def do_history(self, arg, opts):
16101610
if arg:
16111611
# If a character indicating a slice is present, retrieve a slice of the history
16121612
if '..' in arg or ':' in arg:
1613-
# Get a slice of history
1614-
history = self.history.span(arg)
1613+
try:
1614+
# Get a slice of history
1615+
history = self.history.span(arg)
1616+
except IndexError:
1617+
history = self.history.get(arg)
16151618
else:
16161619
# Get item(s) from history by index or string search
16171620
history = self.history.get(arg)

tests/test_cmd2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ def test_history_with_span_end(base_app):
206206
""")
207207
assert out == expected
208208

209+
def test_history_with_span_index_error(base_app):
210+
run_cmd(base_app, 'help')
211+
run_cmd(base_app, 'help history')
212+
run_cmd(base_app, '!ls -hal :')
213+
out = run_cmd(base_app, 'history "hal :"')
214+
expected = normalize("""
215+
-------------------------[3]
216+
!ls -hal :
217+
""")
218+
assert out == expected
219+
209220

210221
def test_base_cmdenvironment(base_app):
211222
out = run_cmd(base_app, 'cmdenvironment')

0 commit comments

Comments
 (0)