Esempio n. 1
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
Esempio n. 2
0
def test_dispatcher_pre_parsing():
    """Parses and return global arguments."""
    groups = [CommandGroup("title", [create_command("somecommand")])]
    dispatcher = Dispatcher(groups)
    global_args = dispatcher.pre_parse_args(["-q", "somecommand"])
    assert global_args == {"help": False, "verbose": False, "quiet": True, "trace": False}
Esempio n. 3
0
def test_detailed_help_text():
    """All different parts for the detailed help, showing all commands."""
    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', 'Group 1 description', [cmd6, cmd2]),
        ('group3', 'Group 3 help text', [cmd7]),
        ('group2', 'Group 2 stuff', [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_detailed_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.

        Commands can be classified as follows:

        Group 1 description:
            cmd6-really-long:  More help.
                   command-2:  Cmd help.

        Group 3 help text:
                        cmd7:  More help.

        Group 2 stuff:
                        cmd3:  Extremely super crazy long super crazy long super
                               crazy long super crazy long super crazy long
                               help.
                        cmd4:  Some help.
                        cmd5:  More help.
                        cmd1:  Cmd help which is very long but whatever.

        For more information about a specific command, run 'charmcraft help <command>'.
    """)
    assert text == expected
Esempio n. 4
0
def test_detailed_help_text(help_builder):
    """All different parts for the detailed help, showing all commands."""
    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 = [
        CommandGroup("Group 1 description", [cmd6, cmd2]),
        CommandGroup("Group 3 help text", [cmd7]),
        CommandGroup("Group 2 stuff", [cmd3, cmd4, cmd5, cmd1]),
    ]
    fake_summary = 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."),
    ]

    help_builder.init("testapp", fake_summary, command_groups)
    text = help_builder.get_detailed_help(global_options)

    expected = textwrap.dedent("""\
        Usage:
            testapp [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.

        Commands can be classified as follows:

        Group 1 description:
            cmd6-really-long:  More help.
                   command-2:  Cmd help.

        Group 3 help text:
                        cmd7:  More help.

        Group 2 stuff:
                        cmd3:  Extremely super crazy long super crazy long super
                               crazy long super crazy long super crazy long
                               help.
                        cmd4:  Some help.
                        cmd5:  More help.
                        cmd1:  Cmd help which is very long but whatever.

        For more information about a specific command, run 'charmcraft help <command>'.
    """)
    assert text == expected