Choices Module
Custom input handlers for Parameters to restrict allowed values to a set of choices.
- author:
Doug Skrypa
- class cli_command_parser.inputs.choices.Choices(choices: Collection[T], type: TypeFunc = None, case_sensitive: Bool = True)[source]
Bases:
_ChoicesBase
[T
]Validates that values are members of the collection of allowed values.
- Parameters:
choices¶ – A collection of choices allowed for a given Parameter.
type¶ – Called before evaluating whether a value matches one of the allowed choices, if provided. Must accept a single string argument.
case_sensitive¶ – Whether choices should be case-sensitive. Defaults to True. If the choices values are not all strings, then this cannot be set to False.
- class cli_command_parser.inputs.choices.ChoiceMap(choices: Mapping[Any, T], *args, **kwargs)[source]
Bases:
Choices
[T
]Similar to
Choices
, but requires a mapping for allowed values.- Parameters:
choices¶ – Mapping (dict) where for a given key=value pair, the key is the value that is expected to be provided as an argument, and the value is what should be stored in the Parameter for that argument.
type¶ – Called before evaluating whether a value matches one of the allowed choices, if provided. Must accept a single string argument.
case_sensitive¶ – Whether choices should be case-sensitive. Defaults to True. If the choices keys are not all strings, then this cannot be set to False.