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"], "--") == []
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"]
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"]
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"]
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")
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"]
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
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
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
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')