Python click.CommandCollection() Examples

The following are 2 code examples of click.CommandCollection(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module click , or try the search function .
Example #1
Source File: test_command_collection.py    From click-repl with MIT License 6 votes vote down vote up
def test_completion():
    @click.group()
    def foo_group():
        pass

    @foo_group.command()
    def foo_cmd():
        pass

    @click.group()
    def foobar_group():
        pass

    @foobar_group.command()
    def foobar_cmd():
        pass

    c = ClickCompleter(click.CommandCollection(sources=[foo_group, foobar_group]))
    completions = list(c.get_completions(Document(u"foo")))

    assert set(x.text for x in completions) == set([u"foo_cmd", u"foobar_cmd"]) 
Example #2
Source File: cli.py    From manage with ISC License 6 votes vote down vote up
def init_cli(cli_obj, reset=False):
    if reset:
        global MANAGE_DICT
        MANAGE_DICT = {}
    sys.path.insert(0, ".")
    load_manage_dict_from_sys_args()
    cli.help = MANAGE_DICT.get("help_text", "{project_name} Interactive shell!").format(
        **MANAGE_DICT
    )
    load_groups(cli, MANAGE_DICT)
    load_commands(cli, MANAGE_DICT)
    manager = click.CommandCollection(help=cli.help, no_args_is_help=False)
    manager.add_source(cli)
    load_command_sources(manager, MANAGE_DICT)
    for item in MANAGE_DICT.get("disabled", []):
        cli.commands.pop(item, None)
    return manager