示例#1
0
def create_main_parser():
    # type: () -> ConfigOptionParser
    """Creates and returns the main parser for pip's CLI
    """

    parser_kw = {
        "usage": "\n%prog <command> [options]",
        "add_help_option": False,
        "formatter": UpdatingDefaultsHelpFormatter(),
        "name": "global",
        "prog": get_prog(),
    }

    parser = ConfigOptionParser(**parser_kw)
    parser.disable_interspersed_args()

    parser.version = get_pip_version()

    # add the general options
    gen_opts = cmdoptions.make_option_group(cmdoptions.general_group, parser)
    parser.add_option_group(gen_opts)

    # so the help formatter knows
    parser.main = True  # type: ignore

    # create command listing for description
    description = [""] + [
        "{name:27} {command_info.summary}".format(**locals())
        for name, command_info in commands_dict.items()
    ]
    parser.description = "\n".join(description)

    return parser
示例#2
0
def create_main_parser():
    # type: () -> ConfigOptionParser
    """Creates and returns the main parser for pip's CLI
    """

    parser_kw = {
        'usage': '\n%prog <command> [options]',
        'add_help_option': False,
        'formatter': UpdatingDefaultsHelpFormatter(),
        'name': 'global',
        'prog': get_prog(),
    }

    parser = ConfigOptionParser(**parser_kw)
    parser.disable_interspersed_args()

    parser.version = get_pip_version()

    # add the general options
    gen_opts = cmdoptions.make_option_group(cmdoptions.general_group, parser)
    parser.add_option_group(gen_opts)

    # so the help formatter knows
    parser.main = True  # type: ignore

    # create command listing for description
    description = [''] + [
        '%-27s %s' % (name, command_info.summary)
        for name, command_info in commands_dict.items()
    ]
    parser.description = '\n'.join(description)

    return parser
示例#3
0
def create_main_parser():
    # type: () -> ConfigOptionParser
    """Creates and returns the main parser for pip's CLI
    """

    parser = ConfigOptionParser(
        usage='\n%prog <command> [options]',
        add_help_option=False,
        formatter=UpdatingDefaultsHelpFormatter(),
        name='global',
        prog=get_prog(),
    )
    parser.disable_interspersed_args()

    parser.version = get_pip_version()

    # add the general options
    gen_opts = cmdoptions.make_option_group(cmdoptions.general_group, parser)
    parser.add_option_group(gen_opts)

    # so the help formatter knows
    parser.main = True  # type: ignore

    # create command listing for description
    description = [''] + [
        '{name:27} {command_info.summary}'.format(**locals())
        for name, command_info in commands_dict.items()
    ]
    parser.description = '\n'.join(description)

    return parser
示例#4
0
def test_help_commands_equally_functional(in_memory_pip):
    """
    Test if `pip help` and 'pip --help' behave the same way.
    """
    results = list(map(in_memory_pip.pip, ('help', '--help')))
    results.append(in_memory_pip.pip())

    out = map(lambda x: x.stdout, results)
    ret = map(lambda x: x.returncode, results)

    msg = '"pip --help" != "pip help" != "pip"'
    assert len(set(out)) == 1, 'output of: ' + msg
    assert sum(ret) == 0, 'exit codes of: ' + msg
    assert all(len(o) > 0 for o in out)

    for name, cls in commands.items():
        assert (in_memory_pip.pip('help', name).stdout == in_memory_pip.pip(
            name, '--help').stdout != "")
示例#5
0
def test_help_commands_equally_functional(in_memory_pip):
    """
    Test if `pip help` and 'pip --help' behave the same way.
    """
    results = list(map(in_memory_pip.pip, ('help', '--help')))
    results.append(in_memory_pip.pip())

    out = map(lambda x: x.stdout, results)
    ret = map(lambda x: x.returncode, results)

    msg = '"pip --help" != "pip help" != "pip"'
    assert len(set(out)) == 1, 'output of: ' + msg
    assert sum(ret) == 0, 'exit codes of: ' + msg
    assert all(len(o) > 0 for o in out)

    for name, cls in commands.items():
        assert (
            in_memory_pip.pip('help', name).stdout ==
            in_memory_pip.pip(name, '--help').stdout != ""
        )
示例#6
0
    # add the general options
    gen_opts = cmdoptions.make_option_group(cmdoptions.general_group, parser)
    parser.add_option_group(gen_opts)

    # so the help formatter knows
    parser.main = True  # type: ignore

    # create command listing for description
<<<<<<< HEAD
    command_summaries = get_summaries()
    description = [''] + ['%-27s %s' % (i, j) for i, j in command_summaries]
=======
    description = [''] + [
        '{name:27} {command_info.summary}'.format(**locals())
        for name, command_info in commands_dict.items()
    ]
>>>>>>> e585743114c1741ec20dc76010f96171f3516589
    parser.description = '\n'.join(description)

    return parser


def parse_command(args):
    # type: (List[str]) -> Tuple[str, List[str]]
    parser = create_main_parser()

    # Note: parser calls disable_interspersed_args(), so the result of this
    # call is to split the initial args into the general options before the
    # subcommand and everything else.
    # For example:
示例#7
0
 def get_summaries():
     return ((k, v.summary) for k, v in commands_dict.items())