recline.arg_types.choices module
Original © NetApp 2024
A Choices type allows the CLI command writer to specify a static list of choices for a parameter. Once the body of the function is invoked, it is guaranteed that the validation was done on the parameter to make sure it matched one.
@recline.command(name=”cake make”) def make_cake(flavor: Choices.define([“chocolate”, “vanilla”, “marble”])) -> None:
# We can assume flavor is one of the choices in the body of the function
- class recline.arg_types.choices.Choices
Bases:
ReclineType
The Choices type validates the user input according to a list of possible choices
- static define(available_choices: ~typing.List | ~typing.Callable, cache_choices: bool = False, inexact: bool = False, data_type=<class 'str'>) Choices
A recline.commands.types.Choices is a way to assert that an argument is one of a predefined list.
Prior to being passed to your command, the argument will be compared to the list of defined choices. If it does not match one, an error will be printed.
- Args:
- available_choices: The list of allowable values for the argument or
a callable that will return a list.
- cache_choices: If the available_choices argument was a callable, by
default it will be called each time the list of choices needs to be rendered. But if that callable is expensive, that may not be desirable. In that case, passing cache_choices as True will call the available_choices function only once to get the list and save the result.
- inexact: If set to True, allow the value being validated to contain
the “*”, “|”, or “..” query characters. If these characters are present, then no validation will be done on the value (and validation is assumed to be done on whatever the command is calling)
data_type: The type of data that represents this argument