Ejemplo n.º 1
0
def test_help_option():
    cli = Group(
        "cli",
        commands=[Command("with"),
                  Command("no", add_help_option=False)])
    assert _get_words(cli, ["with"], "--") == ["--help"]
    assert _get_words(cli, ["no"], "--") == []
Ejemplo n.º 2
0
def test_group_command_same_option():
    cli = Group("cli",
                params=[Option(["-a"])],
                commands=[Command("x", params=[Option(["-a"])])])
    assert _get_words(cli, [], "-") == ["-a", "--help"]
    assert _get_words(cli, ["-a", "a"], "-") == ["--help"]
    assert _get_words(cli, ["-a", "a", "x"], "-") == ["-a", "--help"]
    assert _get_words(cli, ["-a", "a", "x", "-a", "a"], "-") == ["--help"]
Ejemplo n.º 3
0
def test_chained():
    cli = Group(
        "cli",
        chain=True,
        commands=[
            Command("set", params=[Option(["-y"])]),
            Command("start"),
            Group("get", commands=[Command("full")]),
        ],
    )
    assert _get_words(cli, [], "") == ["get", "set", "start"]
    assert _get_words(cli, [], "s") == ["set", "start"]
    assert _get_words(cli, ["set", "start"], "") == ["get"]
    # subcommands and parent subcommands
    assert _get_words(cli, ["get"], "") == ["full", "set", "start"]
    assert _get_words(cli, ["get", "full"], "") == ["set", "start"]
    assert _get_words(cli, ["get"], "s") == ["set", "start"]
Ejemplo n.º 4
0
def test_hidden():
    cli = Group(
        "cli",
        commands=[
            Command(
                "hidden",
                add_help_option=False,
                hidden=True,
                params=[
                    Option(["-a"]),
                    Option(["-b"], type=Choice(["a", "b"]), hidden=True),
                ],
            )
        ],
    )
    assert "hidden" not in _get_words(cli, [], "")
    assert "hidden" not in _get_words(cli, [], "hidden")
    assert _get_words(cli, ["hidden"], "-") == ["-a"]
    assert _get_words(cli, ["hidden", "-b"], "") == ["a", "b"]
Ejemplo n.º 5
0
def main_entry():
    main = Group(chain=False)

    # TODO: Add options
    # @click.option('--debug/--no-debug', default=False, help="Default is --no-debug.")
    # @click.option('-v', '--verbosity', default=0, help='Verbosity level (0-3).')

    for importer, modname, _ in pkgutil.iter_modules(aspire.commands.__path__):
        module = importer.find_module(modname).load_module(modname)
        commands = [
            v for v in module.__dict__.values() if isinstance(v, Command)
        ]
        for command in commands:
            main.add_command(command)

    main.main(prog_name="aspire")
Ejemplo n.º 6
0
def test_group():
    cli = Group("cli",
                params=[Option(["-a"])],
                commands=[Command("x"), Command("y")])
    assert _get_words(cli, [], "") == ["x", "y"]
    assert _get_words(cli, [], "-") == ["-a", "--help"]
Ejemplo n.º 7
0
def test_full_complete(runner, shell, env, expect):
    cli = Group("cli", commands=[Command("a"), Command("b", help="bee")])
    env["_CLI_COMPLETE"] = f"{shell}_complete"
    result = runner.invoke(cli, env=env)
    assert result.output == expect
Ejemplo n.º 8
0
def test_full_source(runner, shell):
    cli = Group("cli", commands=[Command("a"), Command("b")])
    result = runner.invoke(cli, env={"_CLI_COMPLETE": f"{shell}_source"})
    assert f"_CLI_COMPLETE={shell}_complete" in result.output
Ejemplo n.º 9
0
def test_add_different_name():
    cli = Group("cli", commands={"renamed": Command("original")})
    words = _get_words(cli, [], "")
    assert "renamed" in words
    assert "original" not in words
Ejemplo n.º 10
0
import pkgutil
from click.core import Group, Command
import aspire.commands

if __name__ == "__main__":
    main = Group(chain=False)

    # TODO: Add options
    # @click.option('--debug/--no-debug', default=False, help="Default is --no-debug.")
    # @click.option('-v', '--verbosity', default=0, help='Verbosity level (0-3).')

    for importer, modname, ispkg in pkgutil.iter_modules(
            aspire.commands.__path__):
        module = importer.find_module(modname).load_module(modname)
        commands = [
            v for v in module.__dict__.values() if isinstance(v, Command)
        ]
        for command in commands:
            main.add_command(command)

    main.main(prog_name='aspire')