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: Action

Store 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 --match won’t have their lists merged together, and can be considered independently of one another (i.e. OR).

Parameters:
Return type:

None

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: Action

Store 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:
Return type:

None

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: Action

Store 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:
Return type:

None

class onyo.argparse_helpers.StoreSortOption(option_strings, dest=None, sort_direction='ascending', **kwargs)[source]

Bases: Action

Store 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:
Return type:

None

__init__(option_strings, dest=None, sort_direction='ascending', **kwargs)[source]

Instantiate a StoreSortOption with its sort direction.

The dest attribute is ignored and is hardcoded to 'sort'.

The default attribute 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 to argparse.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 default attribute is used.