diff options
author | kotfu <kotfu@kotfu.net> | 2018-01-15 11:39:19 -0700 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-01-15 11:39:19 -0700 |
commit | 221096865ee1eae7ee0795653f4522b741b3a69b (patch) | |
tree | 824c278405eff61da0c8f50dbf0552114e7de7cc /cmd2.py | |
parent | da0a44888312eefba3f6d8c07efd784875691129 (diff) | |
download | cmd2-git-221096865ee1eae7ee0795653f4522b741b3a69b.tar.gz |
Argument parsing and support currention functionality for #252
still need to add support for -o, -r, and -e options.
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 28 |
1 files changed, 16 insertions, 12 deletions
@@ -1683,24 +1683,28 @@ Paths or arguments that contain spaces must be enclosed in quotes exit_msg = 'Leaving IPython, back to {}'.format(sys.argv[0]) embed(banner1=banner, exit_msg=exit_msg) - show_parser = argparse.ArgumentParser( - description='list past commands issued', + history_parser = argparse.ArgumentParser( + description='run, edit, and save past commands', formatter_class=argparse.RawTextHelpFormatter, ) - show_parser.add_argument('-s', '--script', action='store_true', help='script format; no separation lines') - _history_arg_help = """no arg list all -arg is integer by index -a..b, a:b, a:, ..b by indices (inclusive) -arg is string containing string -arg is /regex/ matching regular expression regex""" - show_parser.add_argument('arg', nargs='*', help=_history_arg_help) - - @with_argument_parser(show_parser) + history_parser.add_argument('-s', '--script', action='store_true', help='script format; no separation lines') + history_parser_group = history_parser.add_mutually_exclusive_group() + history_parser_group.add_argument('-r', '--run', action='store_true', help='run selected history items') + history_parser_group.add_argument('-e', '--edit', action='store_true', help='edit and then run selected history items') + history_parser_group.add_argument('-o', '--output-file', metavar='FILE', type=argparse.FileType('w'), help='output to file') + _history_arg_help = """empty all history items +a one history item by number +a..b, a:b, a:, ..b items by indices (inclusive) +[string] items containing string +/regex/ items matching regular expression""" + history_parser.add_argument('arg', nargs='?', help=_history_arg_help) + + @with_argument_parser(history_parser) def do_history(self, args): # If an argument was supplied, then retrieve partial contents of the history if args.arg: # If a character indicating a slice is present, retrieve a slice of the history - arg = args.arg[0] + arg = args.arg if '..' in arg or ':' in arg: try: # Get a slice of history |