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]
def test_completion_item_data(): c = CompletionItem("test", a=1) assert c.a == 1 assert c.b is None
class SearchOrderChoice(CompleteChoice): completion_items: list[CompletionItem] = [ CompletionItem("asc", help="Ascending order"), CompletionItem("desc", help="Descending order"), ]
class ClearChoice(CompleteChoice): completion_items: list[CompletionItem] = [ CompletionItem("clear", "Clear history") ]
def shell_complete(self, _ctx, _param, incomplete): from click.shell_completion import CompletionItem return [CompletionItem(c) for c in self.get_completions(incomplete)]