def _create_parser(): """Create a parser for the "history" command.""" p = argparse.ArgumentParser(prog='history', description='Tools for dealing with history') subp = p.add_subparsers(title='action', dest='action') # show action show = subp.add_parser('show', help='displays current history, default action') show.add_argument('-r', dest='reverse', default=False, action='store_true', help='reverses the direction') show.add_argument('n', nargs='?', default=None, help='display n\'th history entry if n is a simple int, ' 'or range of entries if it is Python slice notation') # 'id' subcommand subp.add_parser('id', help='displays the current session id') # 'file' subcommand subp.add_parser('file', help='displays the current history filename') # 'info' subcommand info = subp.add_parser('info', help=('displays information about the ' 'current history')) info.add_argument('--json', dest='json', default=False, action='store_true', help='print in JSON format') # diff diff = subp.add_parser('diff', help='diffs two xonsh history files') diff_history._create_parser(p=diff) # replay, dynamically from xonsh import replay rp = subp.add_parser('replay', help='replays a xonsh history file') replay._create_parser(p=rp) _MAIN_ACTIONS['replay'] = replay._main_action # gc gcp = subp.add_parser('gc', help='launches a new history garbage collector') gcp.add_argument('--size', nargs=2, dest='size', default=None, help=('next two arguments represent the history size and ' 'units; e.g. "--size 8128 commands"')) bgcp = gcp.add_mutually_exclusive_group() bgcp.add_argument('--blocking', dest='blocking', default=True, action='store_true', help=('ensures that the gc blocks the main thread, ' 'default True')) bgcp.add_argument('--non-blocking', dest='blocking', action='store_false', help='makes the gc non-blocking, and thus return sooner') return p
def _create_parser(): global _HIST_PARSER if _HIST_PARSER is not None: return _HIST_PARSER from argparse import ArgumentParser p = ArgumentParser(prog="history", description="Tools for dealing with history") subp = p.add_subparsers(title="action", dest="action") # show action show = subp.add_parser("show", help="displays current history, default action") show.add_argument("-r", dest="reverse", default=False, action="store_true", help="reverses the direction") show.add_argument( "n", nargs="?", default=None, help="display n'th history entry if n is a simple int, " "or range of entries if it is Python slice notation", ) # id idp = subp.add_parser("id", help="displays the current session id") # file fp = subp.add_parser("file", help="displays the current history filename") # info info = subp.add_parser("info", help="displays information about the current history") info.add_argument("--json", dest="json", default=False, action="store_true", help="print in JSON format") # diff diff = subp.add_parser("diff", help="diffs two xonsh history files") diff_history._create_parser(p=diff) # replay, dynamically from xonsh import replay rp = subp.add_parser("replay", help="replays a xonsh history file") replay._create_parser(p=rp) _MAIN_ACTIONS["replay"] = replay._main_action # gc gcp = subp.add_parser("gc", help="launches a new history garbage collector") gcp.add_argument( "--size", nargs=2, dest="size", default=None, help="next two arguments represent the history size and units, " 'eg "--size 8128 commands"', ) bgcp = gcp.add_mutually_exclusive_group() bgcp.add_argument( "--blocking", dest="blocking", default=True, action="store_true", help="ensures that the gc blocks the main thread, default True", ) bgcp.add_argument( "--non-blocking", dest="blocking", action="store_false", help="makes the gc non-blocking, and thus return sooner", ) # set and return _HIST_PARSER = p return p
def _create_parser(): global _HIST_PARSER if _HIST_PARSER is not None: return _HIST_PARSER from argparse import ArgumentParser p = ArgumentParser(prog='history', description='Tools for dealing with history') subp = p.add_subparsers(title='action', dest='action') # show action show = subp.add_parser('show', help='displays current history, default action') show.add_argument('-r', dest='reverse', default=False, action='store_true', help='reverses the direction') show.add_argument('n', nargs='?', default=None, help='displays n current history entries, n may be an int or use ' 'Python slice notation') # id idp = subp.add_parser('id', help='displays the current session id') # file fp = subp.add_parser('file', help='displays the current history filename') # info info = subp.add_parser('info', help='displays information about the current history') info.add_argument('--json', dest='json', default=False, action='store_true', help='print in JSON format') # diff diff = subp.add_parser('diff', help='diffs two xonsh history files') diff_history._create_parser(p=diff) # replay, dynamically from xonsh import replay rp = subp.add_parser('replay', help='replays a xonsh history file') replay._create_parser(p=rp) _MAIN_ACTIONS['replay'] = replay._main_action # gc gcp = subp.add_parser('gc', help='launches a new history garbage collector') gcp.add_argument('--size', nargs=2, dest='size', default=None, help='next two arguments represent the history size and units, ' 'eg "--size 8128 commands"') bgcp = gcp.add_mutually_exclusive_group() bgcp.add_argument('--blocking', dest='blocking', default=True, action='store_true', help='ensures that the gc blocks the main thread, default True') bgcp.add_argument('--non-blocking', dest='blocking', action='store_false', help='makes the gc non-blocking, and thus return sooner') # set and return _HIST_PARSER = p return p
def _create_parser(): global _HIST_PARSER if _HIST_PARSER is not None: return _HIST_PARSER from argparse import ArgumentParser p = ArgumentParser(prog='history', description='Tools for dealing with history') subp = p.add_subparsers(title='action', dest='action') # show action show = subp.add_parser('show', help='displays current history, default action') show.add_argument('-r', dest='reverse', default=False, action='store_true', help='reverses the direction') show.add_argument( 'n', nargs='?', default=None, help='displays n current history entries, n may be an int or use ' 'Python slice notation') # id idp = subp.add_parser('id', help='displays the current session id') # file fp = subp.add_parser('file', help='displays the current history filename') # info info = subp.add_parser( 'info', help='displays information about the current history') info.add_argument('--json', dest='json', default=False, action='store_true', help='print in JSON format') # diff diff = subp.add_parser('diff', help='diffs two xonsh history files') diff_history._create_parser(p=diff) # replay, dynamically from xonsh import replay rp = subp.add_parser('replay', help='replays a xonsh history file') replay._create_parser(p=rp) _MAIN_ACTIONS['replay'] = replay._main_action # gc gcp = subp.add_parser('gc', help='launches a new history garbage collector') gcp.add_argument( '--size', nargs=2, dest='size', default=None, help='next two arguments represent the history size and units, ' 'eg "--size 8128 commands"') bgcp = gcp.add_mutually_exclusive_group() bgcp.add_argument( '--blocking', dest='blocking', default=True, action='store_true', help='ensures that the gc blocks the main thread, default True') bgcp.add_argument('--non-blocking', dest='blocking', action='store_false', help='makes the gc non-blocking, and thus return sooner') # set and return _HIST_PARSER = p return p