class documentation

class Choice(ParamType):

View In Hierarchy

The choice type allows a value to be checked against a fixed set of supported values. All of these values have to be strings.

You should only pass a list or tuple of choices. Other iterables (like generators) may lead to surprising results.

The resulting value will always be one of the originally passed choices regardless of case_sensitive or any ctx.token_normalize_func being specified.

See :ref:`choice-opts` for an example.

Parameters
case​_sensitiveSet to false to make choices case insensitive. Defaults to true.
Method __init__ Undocumented
Method __repr__ Undocumented
Method convert Convert the value to the correct type. This is not called if the value is None (the missing value).
Method get​_metavar Returns the metavar default for this param if it provides one.
Method get​_missing​_message Optionally might return extra information about a missing parameter.
Method shell​_complete Complete choices that start with the incomplete value.
Method to​_info​_dict Gather information that could be useful for a tool generating user-facing documentation.
Class Variable name Undocumented
Instance Variable case​_sensitive Undocumented
Instance Variable choices Undocumented

Inherited from ParamType:

Method __call__ Undocumented
Method fail Helper method to fail with an invalid value message.
Method split​_envvar​_value Given a value from an environment variable this splits it up into small chunks depending on the defined envvar list splitter.
Class Variable arity Undocumented
Class Variable envvar​_list​_splitter Undocumented
Class Variable is​_composite Undocumented
def __init__(self, choices, case_sensitive=True):

Undocumented

Parameters
choices:t.Sequence[str]Undocumented
case​_sensitive:boolUndocumented
def __repr__(self):

Undocumented

Returns
strUndocumented
def convert(self, value, param, ctx):

Convert the value to the correct type. This is not called if the value is None (the missing value).

This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.

The param and ctx arguments may be None in certain situations, such as when converting prompt input.

If the value cannot be converted, call fail with a descriptive message.

Parameters
value:t.AnyThe value to convert.
param:t.Optional[Parameter]The parameter that is using this type to convert its value. May be None.
ctx:t.Optional[Context]The current context that arrived at this value. May be None.
Returns
t.AnyUndocumented
def get_metavar(self, param):
Returns the metavar default for this param if it provides one.
Parameters
param:ParameterUndocumented
Returns
strUndocumented
def get_missing_message(self, param):

Optionally might return extra information about a missing parameter.

New in version 2.0.
Parameters
param:ParameterUndocumented
Returns
strUndocumented
def shell_complete(self, ctx, param, incomplete):

Complete choices that start with the incomplete value.

New in version 8.0.
Parameters
ctx:ContextInvocation context for this command.
param:ParameterThe parameter that is requesting completion.
incomplete:strValue being completed. May be empty.
Returns
t.List[CompletionItem]Undocumented
def to_info_dict(self):

Gather information that could be useful for a tool generating user-facing documentation.

Use click.Context.to_info_dict to traverse the entire CLI structure.

New in version 8.0.
Returns
t.Dict[str, t.Any]Undocumented
name: str =

Undocumented

case_sensitive =

Undocumented

choices =

Undocumented