_hist_parse_args ref/fix for some cases

This commit is contained in:
Konstantinos Tsakiltzidis 2016-08-04 14:10:44 +03:00
parent d3793a3f99
commit 4ef9322054

View file

@ -355,7 +355,7 @@ def _hist_create_parser():
help='show only commands after timestamp') help='show only commands after timestamp')
show.add_argument('session', nargs='?', choices=_HIST_SESSIONS.keys(), default='session', show.add_argument('session', nargs='?', choices=_HIST_SESSIONS.keys(), 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=argparse.REMAINDER, default=[], show.add_argument('slices', nargs='*', default=None,
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')
@ -661,24 +661,18 @@ def _hist_parse_args(args):
args = ['show', 'session'] args = ['show', 'session']
elif args[0] not in _HIST_MAIN_ACTIONS and args[0] not in ('-h', '--help'): elif args[0] not in _HIST_MAIN_ACTIONS and args[0] not in ('-h', '--help'):
args = ['show', 'session'] + args args = ['show', 'session'] + args
elif args[0] == 'show': if args[0] == 'show':
opt_arg_index = 0 if not any(a in _HIST_SESSIONS for a in args):
found_session = False args.insert(1, 'session')
for i, a in enumerate(args[1:], 1): ns, slices = parser.parse_known_args(args)
if a in _HIST_SESSIONS: if slices:
found_session = True if not ns.slices:
break ns.slices = slices
elif a.startswith(('-', '+')) and a.lstrip('-+').isalpha():
# get last optional arg index, before slices
if a in ('-t', '+t'):
i += 1 # include timestamp value
opt_arg_index = i
else: else:
# everything else is considered a slice argument ns.slices.extend(slices)
break else:
if not found_session: # insert after optional args ns = parser.parse_args(args)
args.insert(opt_arg_index + 1, 'session') return ns
return parser.parse_args(args)
def history_main(args=None, stdin=None): def history_main(args=None, stdin=None):