Ejemplo n.º 1
0
def get_general_help(detailed=False):
    """Produce the "general charmcraft" help."""
    options = _get_global_options()
    if detailed:
        help_text = helptexts.get_detailed_help(COMMAND_GROUPS, options)
    else:
        help_text = helptexts.get_full_help(COMMAND_GROUPS, options)
    return help_text
Ejemplo n.º 2
0
def test_default_help_text():
    """All different parts for the default help."""
    cmd1 = create_command("cmd1",
                          "Cmd help which is very long but whatever.",
                          common_=True)
    cmd2 = create_command("command-2", "Cmd help.", common_=True)
    cmd3 = create_command("cmd3",
                          "Extremely " + "super crazy long " * 5 + " help.",
                          common_=True)
    cmd4 = create_command("cmd4", "Some help.")
    cmd5 = create_command("cmd5", "More help.")
    cmd6 = create_command("cmd6-really-long", "More help.", common_=True)
    cmd7 = create_command("cmd7", "More help.")

    command_groups = [
        ("group1", "help text for g1", [cmd6, cmd2]),
        ("group3", "help text for g3", [cmd7]),
        ("group2", "help text for g2", [cmd3, cmd4, cmd5, cmd1]),
    ]
    fake_summary = textwrap.indent(
        textwrap.dedent("""
        This is the summary for
        the whole program.
    """),
        "    ",
    )
    global_options = [
        ("-h, --help", "Show this help message and exit."),
        ("-q, --quiet", "Only show warnings and errors, not progress."),
    ]

    with patch("charmcraft.helptexts.GENERAL_SUMMARY", fake_summary):
        text = get_full_help(command_groups, global_options)

    expected = textwrap.dedent("""\
        Usage:
            charmcraft [help] <command>

        Summary:
            This is the summary for
            the whole program.

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

        Starter commands:
                        cmd1:  Cmd help which is very long but whatever.
                        cmd3:  Extremely super crazy long super crazy long super
                               crazy long super crazy long super crazy long
                               help.
            cmd6-really-long:  More help.
                   command-2:  Cmd help.

        Commands can be classified as follows:
                      group1:  cmd6-really-long, command-2
                      group2:  cmd1, cmd3, cmd4, cmd5
                      group3:  cmd7

        For more information about a command, run 'charmcraft help <command>'.
        For a summary of all commands, run 'charmcraft help --all'.
    """)
    assert text == expected