Beispiel #1
0
def test_command_help_text_loneranger(config):
    """All different parts for a specific command that's the only one in its group."""
    overview = textwrap.dedent("""
        Quite some long text.
    """)
    cmd1 = create_command("somecommand",
                          "Command one line help.",
                          overview_=overview)
    cmd2 = create_command("other-cmd-2", "Some help.")
    command_groups = [
        ("group1", "help text for g1", [cmd1]),
        ("group2", "help text for g2", [cmd2]),
    ]

    options = [
        ("-h, --help", "Show this help message and exit."),
        ("-q, --quiet", "Only show warnings and errors, not progress."),
    ]

    text = get_command_help(command_groups, cmd1("group1", config), options)

    expected = textwrap.dedent("""\
        Usage:
            charmcraft somecommand [options]

        Summary:
            Quite some long text.

        Options:
             -h, --help:  Show this help message and exit.
            -q, --quiet:  Only show warnings and errors, not progress.

        For a summary of all commands, run 'charmcraft help --all'.
    """)
    assert text == expected
Beispiel #2
0
def get_command_help(parser, command):
    """Produce the complete help message for a command."""
    options = _get_global_options()

    for action in parser._actions:
        # store the different options if present, otherwise it's just the dest
        if action.option_strings:
            options.append((', '.join(action.option_strings), action.help))
        else:
            options.append((action.dest, action.help))

    help_text = helptexts.get_command_help(COMMAND_GROUPS, command, options)
    return help_text
Beispiel #3
0
def test_command_help_text_no_parameters(config):
    """All different parts for a specific command help that doesn't have parameters."""
    overview = textwrap.dedent(
        """
        Quite some long text.

        Multiline!
    """
    )
    cmd1 = create_command("somecommand", "Command one line help.", overview_=overview)
    cmd2 = create_command("other-cmd-2", "Some help.")
    cmd3 = create_command("other-cmd-3", "Some help.")
    cmd4 = create_command("other-cmd-4", "Some help.")
    command_groups = [
        ("group1", "help text for g1", [cmd1, cmd2, cmd4]),
        ("group2", "help text for g2", [cmd3]),
    ]

    options = [
        ("-h, --help", "Show this help message and exit."),
        ("-q, --quiet", "Only show warnings and errors, not progress."),
        ("--name", "The name of the charm."),
        ("--revision", "The revision to release (defaults to latest)."),
    ]

    text = get_command_help(command_groups, cmd1("group1", config), options)

    expected = textwrap.dedent(
        """\
        Usage:
            charmcraft somecommand [options]

        Summary:
            Quite some long text.

            Multiline!

        Options:
             -h, --help:  Show this help message and exit.
            -q, --quiet:  Only show warnings and errors, not progress.
                 --name:  The name of the charm.
             --revision:  The revision to release (defaults to latest).

        See also:
            other-cmd-2
            other-cmd-4

        For a summary of all commands, run 'charmcraft help --all'.
    """
    )
    assert text == expected
Beispiel #4
0
def test_command_help_text_with_parameters(config):
    """All different parts for a specific command help that has parameters."""
    overview = textwrap.dedent(
        """
        Quite some long text.
    """
    )
    cmd1 = create_command("somecommand", "Command one line help.", overview_=overview)
    cmd2 = create_command("other-cmd-2", "Some help.")
    command_groups = [
        ("group1", "help text for g1", [cmd1, cmd2]),
    ]

    options = [
        ("-h, --help", "Show this help message and exit."),
        ("name", "The name of the charm."),
        ("--revision", "The revision to release (defaults to latest)."),
        ("extraparam", "Another parameter.."),
        ("--other-option", "Other option."),
    ]

    text = get_command_help(command_groups, cmd1("group1", config), options)

    expected = textwrap.dedent(
        """\
        Usage:
            charmcraft somecommand [options] <name> <extraparam>

        Summary:
            Quite some long text.

        Options:
                -h, --help:  Show this help message and exit.
                --revision:  The revision to release (defaults to latest).
            --other-option:  Other option.

        See also:
            other-cmd-2

        For a summary of all commands, run 'charmcraft help --all'.
    """
    )
    assert text == expected