コード例 #1
0
    def shell_complete(self, ctx: "Context", param: "Parameter",
                       incomplete: str) -> t.List["CompletionItem"]:
        """Complete choices that start with the incomplete value.

        :param ctx: Invocation context for this command.
        :param param: The parameter that is requesting completion.
        :param incomplete: Value being completed. May be empty.

        .. versionadded:: 8.0
        """
        from click.shell_completion import CompletionItem

        str_choices = map(str, self.choices)

        if self.case_sensitive:
            matched = (c for c in str_choices if c.startswith(incomplete))
        else:
            incomplete = incomplete.lower()
            matched = (c for c in str_choices
                       if c.lower().startswith(incomplete))

        return [CompletionItem(c) for c in matched]
コード例 #2
0
def test_completion_item_data():
    c = CompletionItem("test", a=1)
    assert c.a == 1
    assert c.b is None
コード例 #3
0
class SearchOrderChoice(CompleteChoice):
    completion_items: list[CompletionItem] = [
        CompletionItem("asc", help="Ascending order"),
        CompletionItem("desc", help="Descending order"),
    ]
コード例 #4
0
class ClearChoice(CompleteChoice):
    completion_items: list[CompletionItem] = [
        CompletionItem("clear", "Clear history")
    ]
コード例 #5
0
    def shell_complete(self, _ctx, _param, incomplete):
        from click.shell_completion import CompletionItem

        return [CompletionItem(c) for c in self.get_completions(incomplete)]