Ligare.programming.cli.argparse
Libraries for use with argparse.
Functions
Associate an argument with another, preventing the two from sharing the same value. |
|
|
Disallow a set of values for the argument argument_name. |
Classes
|
Checks for duplicated values for the argument using this Action. |
|
Checks if one or more paths specified are valid paths. |
- class Ligare.programming.cli.argparse.DisallowDuplicateValues(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]
Checks for duplicated values for the argument using this Action. If a value is duplicated, an ArgumentError is raised. Otherwise, the argument is treated as a “Append” action, and the value is added to a list of values for that argument.
- Parameters:
Action (DisallowDuplicateValues) – self
- Raises:
ArgumentError – Raised when a value for the argument is duplicated
- class Ligare.programming.cli.argparse.PathExists(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]
Checks if one or more paths specified are valid paths.
- Parameters:
Action (PathExists) – self
- Raises:
ArgumentError – Raised when a value is not a path, or the path does not exist.
- Ligare.programming.cli.argparse.associate_disallow_duplicate_values(associated_arg)[source]
Associate an argument with another, preventing the two from sharing the same value. If the values are not equivalent, the action then falls back to DisallowDuplicateValues.
- Parameters:
associated_arg (str) – The argument with which to associate the argument that this Action is applied to.
- Raises:
ArgumentError – Raised if the value of the argument using this Action is equivalent to the argument it is associated with.
- Return AssociatedDisallowDuplicateValues:
- Ligare.programming.cli.argparse.disallow(values, argument_name, type=None)[source]
Disallow a set of values for the argument argument_name. If the value given for argument_name is in the list values, an ArgumentTypeError is raised.
disallow acts as a “pass-through” for setting the type of a parameter. It operates by first checking whether the value given is disallowed, and then uses type to return the new object as if that same type had been given directly to argparse without using disallow.
If type is not specified, value is returned as a string.
- Parameters:
values (list[str]) – A list of values that are _not_ allowed for this argument
argument_name (str) – The name of the argument this applies to
type (Callable[[str], _T] | FileType | None) – The type of the argument to be created, defaults to None