def _xh_create_parser(): """Create a parser for the "history" command.""" p = argparse.ArgumentParser(prog='history', description="try 'history <command> --help' " 'for more info') subp = p.add_subparsers(title='commands', dest='action') # session action show = subp.add_parser( 'show', prefix_chars='-+', help='display history of a session, default command') show.add_argument('-r', dest='reverse', default=False, action='store_true', help='reverses the direction') show.add_argument('-n', dest='numerate', default=False, action='store_true', help='numerate each command') show.add_argument('-t', dest='timestamp', default=False, action='store_true', help='show command timestamps') show.add_argument('-T', dest='end_time', default=None, help='show only commands before timestamp') show.add_argument('+T', dest='start_time', default=None, help='show only commands after timestamp') show.add_argument('-f', dest='datetime_format', default=None, help='the datetime format to be used for' 'filtering and printing') show.add_argument( 'session', nargs='?', choices=_XH_HISTORY_SESSIONS.keys(), default='session', metavar='session', help='{} (default: current session, all is an alias for xonsh)' ''.format(', '.join(map(repr, _XH_HISTORY_SESSIONS.keys())))) show.add_argument('slices', nargs='*', default=None, metavar='slice', help='integer or slice notation') # 'id' subcommand subp.add_parser('id', help='display the current session id') # 'file' subcommand subp.add_parser('file', help='display the current history filename') # 'info' subcommand info = subp.add_parser('info', help=('display information about the ' 'current history')) info.add_argument('--json', dest='json', default=False, action='store_true', help='print in JSON format') # 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') hist = builtins.__xonsh_history__ if isinstance(hist, JsonHistory): # add actions belong only to JsonHistory diff = subp.add_parser('diff', help='diff two xonsh history files') xdh.dh_create_parser(p=diff) import xonsh.replay as xrp replay = subp.add_parser('replay', help='replay a xonsh history file') xrp.replay_create_parser(p=replay) _XH_MAIN_ACTIONS.add('replay') return p
def _xh_create_parser(): """Create a parser for the "history" command.""" p = argparse.ArgumentParser( prog="history", description="try 'history <command> --help' " "for more info" ) subp = p.add_subparsers(title="commands", dest="action") # session action show = subp.add_parser( "show", prefix_chars="-+", help="display history of a session, default command" ) show.add_argument( "-r", dest="reverse", default=False, action="store_true", help="reverses the direction", ) show.add_argument( "-n", dest="numerate", default=False, action="store_true", help="numerate each command", ) show.add_argument( "-t", dest="timestamp", default=False, action="store_true", help="show command timestamps", ) show.add_argument( "-T", dest="end_time", default=None, help="show only commands before timestamp" ) show.add_argument( "+T", dest="start_time", default=None, help="show only commands after timestamp" ) show.add_argument( "-f", dest="datetime_format", default=None, help="the datetime format to be used for" "filtering and printing", ) show.add_argument( "-0", dest="null_byte", default=False, action="store_true", help="separate commands by the null character for piping " "history to external filters", ) show.add_argument( "session", nargs="?", choices=_XH_HISTORY_SESSIONS.keys(), default="session", metavar="session", help="{} (default: current session, all is an alias for xonsh)" "".format(", ".join(map(repr, _XH_HISTORY_SESSIONS.keys()))), ) show.add_argument( "slices", nargs="*", default=None, metavar="slice", help="integer or slice notation", ) # 'id' subcommand subp.add_parser("id", help="display the current session id") # 'file' subcommand subp.add_parser("file", help="display the current history filename") # 'info' subcommand info = subp.add_parser( "info", help=("display information about the " "current history") ) info.add_argument( "--json", dest="json", default=False, action="store_true", help="print in JSON format", ) # 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", ) hist = builtins.__xonsh__.history if isinstance(hist, JsonHistory): # add actions belong only to JsonHistory diff = subp.add_parser("diff", help="diff two xonsh history files") xdh.dh_create_parser(p=diff) import xonsh.replay as xrp replay = subp.add_parser("replay", help="replay a xonsh history file") xrp.replay_create_parser(p=replay) _XH_MAIN_ACTIONS.add("replay") return p
def _xh_create_parser(): """Create a parser for the "history" command.""" p = argparse.ArgumentParser(prog='history', description="try 'history <command> --help' " 'for more info') subp = p.add_subparsers(title='commands', dest='action') # session action show = subp.add_parser('show', prefix_chars='-+', help='display history of a session, default command') show.add_argument('-r', dest='reverse', default=False, action='store_true', help='reverses the direction') show.add_argument('-n', dest='numerate', default=False, action='store_true', help='numerate each command') show.add_argument('-t', dest='timestamp', default=False, action='store_true', help='show command timestamps') show.add_argument('-T', dest='end_time', default=None, help='show only commands before timestamp') show.add_argument('+T', dest='start_time', default=None, help='show only commands after timestamp') show.add_argument('-f', dest='datetime_format', default=None, help='the datetime format to be used for' 'filtering and printing') show.add_argument('session', nargs='?', choices=_XH_HISTORY_SESSIONS.keys(), default='session', metavar='session', help='{} (default: current session, all is an alias for xonsh)' ''.format(', '.join(map(repr, _XH_HISTORY_SESSIONS.keys())))) show.add_argument('slices', nargs='*', default=None, metavar='slice', help='integer or slice notation') # 'id' subcommand subp.add_parser('id', help='display the current session id') # 'file' subcommand subp.add_parser('file', help='display the current history filename') # 'info' subcommand info = subp.add_parser('info', help=('display information about the ' 'current history')) info.add_argument('--json', dest='json', default=False, action='store_true', help='print in JSON format') # 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') hist = builtins.__xonsh_history__ if isinstance(hist, JsonHistory): # add actions belong only to JsonHistory diff = subp.add_parser('diff', help='diff two xonsh history files') xdh.dh_create_parser(p=diff) import xonsh.replay as xrp replay = subp.add_parser('replay', help='replay a xonsh history file') xrp.replay_create_parser(p=replay) _XH_MAIN_ACTIONS.add('replay') return p