class ParamType:
Known subclasses: click.types.Choice
, click.types.DateTime
, click.types.File
, click.types.Path
, click.types._NumberParamTypeBase
, click.types.BoolParamType
, click.types.CompositeParamType
, click.types.FuncParamType
, click.types.StringParamType
, click.types.UnprocessedParamType
, click.types.UUIDParameterType
Represents the type of a parameter. Validates and converts values from the command line or Python into the correct type.
To implement a custom type, subclass and implement at least the following:
name
class attribute must be set.convert
must convert string values to the correct type.convert
must accept values that are already the correct
type.Method | __call__ |
Undocumented |
Method | convert |
Convert the value to the correct type. This is not called if the value is None (the missing value). |
Method | fail |
Helper method to fail with an invalid value message. |
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 |
No summary |
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. |
Method | to_info_dict |
Gather information that could be useful for a tool generating user-facing documentation. |
Class Variable | arity |
Undocumented |
Class Variable | envvar_list_splitter |
Undocumented |
Class Variable | is_composite |
Undocumented |
Class Variable | name |
Undocumented |
click.types.Choice
, click.types.DateTime
, click.types.File
, click.types.Path
, click.types.Tuple
, click.types._NumberParamTypeBase
, click.types.BoolParamType
, click.types.FuncParamType
, click.types.StringParamType
, click.types.UnprocessedParamType
, click.types.UUIDParameterType
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.Any | The value to convert. |
param:t.Optional[ | The parameter that is using this type to convert its value. May be None. |
ctx:t.Optional[ | The current context that arrived at this value. May be None. |
Returns | |
t.Any | Undocumented |
click.types.Choice
, click.types.DateTime
Parameters | |
param:Parameter | Undocumented |
Returns | |
t.Optional[ | Undocumented |
click.types.Choice
Optionally might return extra information about a missing parameter.
Parameters | |
param:Parameter | Undocumented |
Returns | |
t.Optional[ | Undocumented |
Return a list of
~click.shell_completion.CompletionItem
objects for the
incomplete value. Most types do not provide completions, but
some do, and this allows custom types to provide custom
completions as well.
Parameters | |
ctx:Context | Invocation context for this command. |
param:Parameter | The parameter that is requesting completion. |
incomplete:str | Value being completed. May be empty. |
Returns | |
t.List[ | Undocumented |
Given a value from an environment variable this splits it up into small chunks depending on the defined envvar list splitter.
If the splitter is set to None
, which means that whitespace splits,
then leading and trailing whitespace is ignored. Otherwise, leading
and trailing splitters usually lead to empty items being included.
Parameters | |
rv:str | Undocumented |
Returns | |
t.Sequence[ | Undocumented |
click.types.Choice
, click.types.DateTime
, click.types.File
, click.types.Path
, click.types.Tuple
, click.types._NumberRangeBase
, click.types.FuncParamType
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.
Returns | |
t.Dict[ | Undocumented |
str
=
click.types.Choice
, click.types.DateTime
, click.types.File
, click.types.FloatRange
, click.types.IntRange
, click.types.Path
, click.types.Tuple
, click.types.BoolParamType
, click.types.FloatParamType
, click.types.FuncParamType
, click.types.IntParamType
, click.types.StringParamType
, click.types.UnprocessedParamType
, click.types.UUIDParameterType
Undocumented