onyo.argparse_helpers module
- class onyo.argparse_helpers.StoreMatchOption(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)[source]
Bases:
ActionStore match statements and retain their order across multiple invocations.
- __call__(parser, namespace, keys, option_string=None)[source]
Store a list of match statements in a list.
This way multiple invocations of
--matchwon’t have their lists merged together, and can be considered independently of one another (i.e.OR).- Parameters:
parser (
ArgumentParser) – ArgumentParser object that contains this action.namespace (
Namespace) – Namespace object returned byargparse.ArgumentParser.parse_args().keys (
list[str]) – List of strings containing match statements.option_string (
str|None(default:None)) – Option string used to invoke this action.
- Return type:
- class onyo.argparse_helpers.StoreMultipleKeyValuePairs(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)[source]
Bases:
ActionStore a list of dictionaries of key-value pairs.
- __call__(parser, namespace, key_values, option_string=None)[source]
Turn a list of ‘KEY=VALUE’ pairs into a list of dictionaries.
Each key can be defined either 1 or N times (where N is the number of dictionaries to be created).
A key that is declared once will apply to all dictionaries.
All keys appearing N times must appear the same number of times. If not, a message will print to standard error and the program will exit with status code 2.
- Parameters:
parser (
ArgumentParser) – ArgumentParser object that contains this action.namespace (
Namespace) – Namespace object returned byargparse.ArgumentParser.parse_args().key_values (
list[str]) – List of strings containing key-value pairs.option_string (
str|None(default:None)) – Option string used to invoke this action.
- Return type:
- class onyo.argparse_helpers.StoreSingleKeyValuePairs(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)[source]
Bases:
ActionStore a dictionary of key-value pairs.
- __call__(parser, namespace, key_values, option_string=None)[source]
Turn a list of ‘KEY=VALUE’ pairs into a dictionary.
Each KEY can be defined once. If defined more than once, a message will print to standard error and the program will exit with status code 2.
- Parameters:
parser (
ArgumentParser) – ArgumentParser object that contains this action.namespace (
Namespace) – Namespace object returned byargparse.ArgumentParser.parse_args().key_values (
list[str]) – List of strings containing key-value pairs.option_string (
str|None(default:None)) – Option string used to invoke this action.
- Return type:
- class onyo.argparse_helpers.StoreSortOption(option_strings, dest=None, sort_direction='ascending', **kwargs)[source]
Bases:
ActionStore keys-to-sort and retain their order across multiple invoking options.
The results destination is hardcoded to
sort. This allows multiple argparse options to use this action and retain the order of arguments passed at the CLI across option flags.- __call__(parser, namespace, keys, option_string=None)[source]
Store keys in a dictionary with the associated sort direction.
- Parameters:
parser (
ArgumentParser) – ArgumentParser object that contains this action.namespace (
Namespace) – Namespace object returned byargparse.ArgumentParser.parse_args().option_string (
str|None(default:None)) – Option string used to invoke this action.
- Return type:
- __init__(option_strings, dest=None, sort_direction='ascending', **kwargs)[source]
Instantiate a
StoreSortOptionwith its sort direction.The
destattribute is ignored and is hardcoded to'sort'.The
defaultattribute is incompatible with this Action, as it’s not possible to know when to use/vs discard the default across multiple options.- Parameters:
option_strings (
Sequence[str]) – List of option strings to associate with this action. Passed toargparse.Action()dest (
str|None(default:None)) – This attribute is ignored and is hardcoded to'sort'.sort_direction (
Literal['ascending','descending'] (default:'ascending')) – Sort direction.**kwargs – Passed to
argparse.Action()
- Raises:
ValueError – The
defaultattribute is used.