PossibleValues¶
PossibleValues is an enumeration that defines special validation modes for flag values. PossibleValues is used in the possible_values parameter of the Flag class to specify whether a flag can accept values and what restrictions are imposed on them.
PossibleValues contains two main values: NEITHER (for flags that cannot accept values) and ALL (for flags accepting any values). This enumeration is used together with string lists and regular expressions to create a flexible validation system.
Note
The validation result is available through the status attribute of the InputFlag instance. For more details, see here.
See also
Documentation for Flag — flag class using PossibleValues.
Documentation for ValidationStatus — validation result of the entered flag.
General information about flags and their usage in the Argenta application
NEITHER¶
1PossibleValues.NEITHER = 'NEITHER'
Indicates that the flag should not have a value.
Flags with this value work as boolean switches: their presence on the command line is information in itself. Attempting to pass a value to such a flag will result in a validation error.
Examples of flags with NEITHER:
--help— help flag--verbose— verbose output flag--force— forced execution flag-A/--all— select all items flag
Usage example:
1from argenta.command import Flag, PossibleValues
2
3# Creating flags without values
4help_flag = Flag(name="help", possible_values=PossibleValues.NEITHER)
5verbose_flag = Flag(name="verbose", possible_values=PossibleValues.NEITHER)
6force_flag = Flag(name="force", possible_values=PossibleValues.NEITHER)
ALL¶
1PossibleValues.ALL = 'ALL'
Indicates that the flag can accept any value.
Flags with this value are universal and do not impose restrictions on the data passed. Validation will always be successful.
Examples of flags with ALL:
--message— arbitrary text message--name— arbitrary name
Usage example:
1from argenta.command import Flag, PossibleValues
2
3# Creating flags with any values
4message_flag = Flag(name="message", possible_values=PossibleValues.ALL)
5name_flag = Flag(name="name", possible_values=PossibleValues.ALL)
The possible_values Parameter¶
PossibleValues is used as one of the possible types for the possible_values parameter when creating a Flag instance.
Available types for possible_values:
PossibleValues.NEITHER: flag without a value.PossibleValues.ALL: flag with any value (default).list[str]: flag with a limited set of values.Pattern[str]: flag with a value validated by a regular expression.
Combined usage example:
1import re
2from argenta.command import Flag, PossibleValues
3
4# Flag without value
5verbose_flag = Flag(name="verbose", possible_values=PossibleValues.NEITHER)
6
7# Flag with any value
8output_flag = Flag(name="output", possible_values=PossibleValues.ALL)
9
10# Flag with a list of valid values
11format_flag = Flag(name="format", possible_values=["json", "xml", "csv", "yaml"])
12
13# Flag with regular expression
14email_flag = Flag(name="email", possible_values=re.compile(r"^[\w\.-]+@[\w\.-]+\.\w+$"))