Helper types
ValidationResult = bool | ErrorMessage
Callback validation result is either boolean or an error message.
ErrorMessage = TypeVar('ErrorMessage')
A string, callback validation error message.
TagValue = TypeVar('TagValue', bound=Any)
Any value. It is being wrapped by a Tag.
ChoicesType = list[TagValue] | tuple[TagValue] | set[TagValue] | dict[RichChoiceLabel, TagValue] | list[Enum] | Type[Enum]
You can denote the choices in many ways.
Either put options in an iterable or to a dict {labels: value}
.
Values might be Tags as well. Let's take a detailed look. We will use the run.choice(ChoicesType)
to illustrate the examples.
Iterables like list
Either put options in an iterable:
Dict for labels
Or to a dict {name: value}
. Then name are used as labels.
Dict with tuples for table
If you use tuple as the keys, they will be joined into a table.
Tags for labels
Alternatively, you may specify the names in Tags
.
Enums
Alternatively, you may use an Enum.
Alternatively, you may use an Enum instance. (Which means the default value is already selected.)
Alternatively, you may use an Enum instances list.
Further examples
See mininterface.choice or EnumTag.choices
for further usage.
DataClass = TypeVar('DataClass')
Any dataclass. Or a pydantic model or attrs.
EnvClass = TypeVar('EnvClass', bound=DataClass)
Any dataclass. Its instance will be available through [miniterface.env] after CLI parsing.