コード例 #1
0
ファイル: history.py プロジェクト: mpacer/xonsh
def _hist_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=_HIST_SESSIONS.keys(),
                      default='session',
                      metavar='session',
                      help='{} (default: current session, all is an alias for xonsh)'
                           ''.format(', '.join(map(repr, _HIST_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')
    # diff
    diff = subp.add_parser('diff', help='diff two xonsh history files')
    _dh_create_parser(p=diff)
    # replay, dynamically
    from xonsh import replay
    rp = subp.add_parser('replay', help='replay a xonsh history file')
    replay._rp_create_parser(p=rp)
    _HIST_MAIN_ACTIONS['replay'] = replay._rp_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
コード例 #2
0
ファイル: history.py プロジェクト: Siecje/xonsh
def _hist_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')
    # session action
    show = subp.add_parser('show', help='displays session history, default action')
    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('session', nargs='?', choices=_HIST_SESSIONS.keys(), default='session',
                      help='Choose a history session, defaults to current session')
    show.add_argument('slices', nargs=argparse.REMAINDER, default=[],
                      help='display history entries or range of entries')
    # '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')
    _dh_create_parser(p=diff)
    # replay, dynamically
    from xonsh import replay
    rp = subp.add_parser('replay', help='replays a xonsh history file')
    replay._rp_create_parser(p=rp)
    _HIST_MAIN_ACTIONS['replay'] = replay._rp_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
コード例 #3
0
def _hist_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')
    _dh_create_parser(p=diff)
    # replay, dynamically
    from xonsh import replay
    rp = subp.add_parser('replay', help='replays a xonsh history file')
    replay._rp_create_parser(p=rp)
    _HIST_MAIN_ACTIONS['replay'] = replay._rp_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
コード例 #4
0
ファイル: history.py プロジェクト: BlaXpirit/xonsh
def _hist_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')
    # session action
    show = subp.add_parser('show', aliases=['session'],
                           help='displays session 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')
    # all action
    xonsh = subp.add_parser('xonsh', aliases=['all'],
                            help='displays history from all sessions')
    xonsh.add_argument('-r', dest='reverse', default=False,
                       action='store_true',
                       help='reverses the direction')
    xonsh.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')
    # zsh action
    zsh = subp.add_parser('zsh', help='displays history from zsh sessions')
    zsh.add_argument('-r', dest='reverse', default=False,
                     action='store_true',
                     help='reverses the direction')
    zsh.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')
    # bash action
    bash = subp.add_parser('bash', help='displays history from bash sessions')
    bash.add_argument('-r', dest='reverse', default=False,
                      action='store_true',
                      help='reverses the direction')
    bash.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')
    _dh_create_parser(p=diff)
    # replay, dynamically
    from xonsh import replay
    rp = subp.add_parser('replay', help='replays a xonsh history file')
    replay._rp_create_parser(p=rp)
    _HIST_MAIN_ACTIONS['replay'] = replay._rp_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