_hist_show deal with multiple slices

This commit is contained in:
laerus 2016-07-19 00:07:35 +03:00
parent d39ac8836a
commit 3cb22ad9c4

View file

@ -375,7 +375,7 @@ def _hist_create_parser():
help='reverses the direction') help='reverses the direction')
show.add_argument('session', nargs='?', choices=HIST_SESSIONS, default='session', show.add_argument('session', nargs='?', choices=HIST_SESSIONS, default='session',
help='Choose a history session, defaults to current session') help='Choose a history session, defaults to current session')
show.add_argument('slices', nargs='*', default=[], show.add_argument('slices', nargs=argparse.REMAINDER, default=[],
help='display history entries or range of entries') help='display history entries or range of entries')
# 'id' subcommand # 'id' subcommand
subp.add_parser('id', help='displays the current session id') subp.add_parser('id', help='displays the current session id')
@ -466,18 +466,19 @@ def _hist_show(ns=None, hist=None, start_index=None, end_index=None,
print("Invalid end time, must be float or datetime.") print("Invalid end time, must be float or datetime.")
idx = None idx = None
if ns: if ns:
idx = ensure_slice(ns.n) _commands = []
if idx is False: for s in ns.slices:
print("{} is not a valid input.".format(ns.n), s = ensure_slice(s)
file=sys.stderr) if s:
return try:
elif isinstance(idx, int): _commands.extend(commands[s])
try: except IndexError:
commands = [commands[idx]] err = "Index likely not in range. Only {} commands."
except IndexError: print(err.format(len(commands)), file=sys.stderr)
err = "Index likely not in range. Only {} commands." return
print(err.format(len(commands))) else:
return if _commands:
commands = _commands
else: else:
idx = slice(start_index, end_index) idx = slice(start_index, end_index)