Nargs Module

Helpers for handling nargs=... for Parameters.

author:

Doug Skrypa

class cli_command_parser.nargs.Nargs(nargs: str | int | Tuple[int, int | None] | Sequence[int] | Set[int] | FrozenSet[int] | range | REMAINDER)[source]

Bases: object

Helper class for validating the number of values provided for a given Parameter. Unifies the handling of different ways of specifying the required number of values.

Acceptable values include ?, *, and +, and they have the same meaning that they have in argparse. Additionally, integers, a range of integers, or a set/tuple of integers are accepted for more specific requirements.

range: range | None
min: int | None
max: int | None
allowed: Collection[int]
variable: bool
satisfied(count: int) bool[source]

Returns True if the minimum number of values have been provided to satisfy the requirements, and if the number of values has not exceeded the maximum allowed. Returns False if the count is below the minimum or above the maximum.

For more advanced use cases, such as range or a set of counts, the count must also match one of the specific numbers provided for this to return True.

max_reached(parsed_values: Collection[Any]) bool[source]
Parameters:

parsed_values – The value(s) parsed so far for a Parameter.

Returns:

True if parsed_values has a length and that length meets or exceeds the maximum count allowed, False otherwise.

property has_upper_bound: bool[source]
property upper_bound: int | float[source]
cli_command_parser.nargs.nargs_min_and_max_sums(nargs_objects: Iterable[Nargs]) tuple[int, int | float][source]