ArgParseAttributes Module

This module implements attribute-classes and a mixin-class which describe options to construct a argparse-based command line processor. All attributes in this module are sub-classes of Attribute.

Base-Classes

ArgParseAttribute

class pyAttributes.ArgParseAttributes.ArgParseAttribute[source]

Bases: Attribute

Base-class for all attributes to describe a argparse-base command line argument parser.

_classes: List[Any] = []

List of classes, this pyAttribute was attached to.

Inheritance diagram:

Inheritance diagram of pyAttributes.ArgParseAttributes.ArgumentAttribute, pyAttributes.ArgParseAttributes.SwitchArgumentAttribute, pyAttributes.ArgParseAttributes.CommonArgumentAttribute, pyAttributes.ArgParseAttributes.CommonSwitchArgumentAttribute, pyAttributes.ArgParseAttributes.CommandAttribute, pyAttributes.ArgParseAttributes.DefaultAttribute, pyAttributes.ArgParseAttributes.CommandGroupAttribute

MixIns

_HandlerMixin

class pyAttributes.ArgParseAttributes._HandlerMixin[source]

Bases: object

A mixin-class that offers a class field for a reference to a handler method and a matching property.

_handler: Callable = None

Reference to a method that is called to handle e.g. a sub-command.

property Handler: Callable

Returns the handler method.

Return type:

Callable

_KwArgsMixin

class pyAttributes.ArgParseAttributes._KwArgsMixin[source]

Bases: object

A mixin-class that offers a class field for named parameters (`**kwargs) and a matching property.

_kwargs: Dict = None

A dictionary of additional keyword parameters.

property KWArgs: Dict

A dictionary of additional named parameters (**kwargs) passed to the attribute. These additional parameters are passed without modification to ArgumentParser.

Return type:

Dict

_ArgsMixin

class pyAttributes.ArgParseAttributes._ArgsMixin[source]

Bases: _KwArgsMixin

A mixin-class that offers a class field for positional parameters (`*args) and a matching property.

_args: Tuple = None

A tuple of additional positional parameters.

property Args: Tuple

A tuple of additional positional parameters (*args) passed to the attribute. These additional parameters are passed without modification to ArgumentParser.

Return type:

Tuple

Helper-Classes

ArgParseMixin

class pyAttributes.ArgParseAttributes.ArgParseMixin(**kwargs)[source]

Bases: AttributeHelperMixin

Mixin-class to implement an argparse-base command line argument processor.

__init__(**kwargs)[source]

The mixin-constructor expects an optional list of named parameters which are passed without modification to the ArgumentParser constructor.

property MainParser: ArgumentParser

Returns the main parser.

Return type:

ArgumentParser

property SubParsers

Returns the sub-parsers.

Attributes

CommandGroupAttribute

class pyAttributes.ArgParseAttributes.CommandGroupAttribute(groupName)[source]

Bases: ArgParseAttribute

Experimental attribute to group sub-commands in groups for better readability in a prog.py --help call.

__init__(groupName)[source]

The constructor expects a ‘groupName’ which can be used to group sub-commands for better readability.

property GroupName: str

Returns the name of the command group.

Return type:

str

_classes: List[Any] = []

List of classes, this pyAttribute was attached to.

DefaultAttribute

class pyAttributes.ArgParseAttributes.DefaultAttribute[source]

Bases: ArgParseAttribute, _HandlerMixin

Marks a handler method is default handler. This method is called if no sub-command is given. It’s an error if more then one method is annotated with this attribute.

_classes: List[Any] = []

List of classes, this pyAttribute was attached to.

CommandAttribute

class pyAttributes.ArgParseAttributes.CommandAttribute(command, **kwargs)[source]

Bases: ArgParseAttribute, _HandlerMixin, _KwArgsMixin

Marks a handler method as responsible for the given ‘command’. This constructs a sub-command parser using add_subparsers().

__init__(command, **kwargs)[source]

The constructor expects a ‘command’ and an optional list of named parameters (keyword arguments) which are passed without modification to add_subparsers().

property Command: str

Returns the ‘command’ a sub-command parser adheres to.

Return type:

str

_classes: List[Any] = []

List of classes, this pyAttribute was attached to.

ArgumentAttribute

class pyAttributes.ArgParseAttributes.ArgumentAttribute(*args, **kwargs)[source]

Bases: ArgParseAttribute, _ArgsMixin

Base-class for all attributes storing arguments.

__init__(*args, **kwargs)[source]

The constructor expects positional (*args) and/or named parameters (**kwargs) which are passed without modification to add_argument().

_classes: List[Any] = []

List of classes, this pyAttribute was attached to.

SwitchArgumentAttribute

class pyAttributes.ArgParseAttributes.SwitchArgumentAttribute(*args, dest, **kwargs)[source]

Bases: ArgumentAttribute

Defines a switch argument like --help.

Some of the named parameters passed to add_argument() are predefined (or overwritten) to create a boolean parameter passed to the registered handler method. The boolean parameter is True if the switch argument is present in the commandline arguments, otherwise False.

__init__(*args, dest, **kwargs)[source]

The constructor expects positional (*args), the destination parameter name dest and/or named parameters (**kwargs) which are passed to add_argument().

To implement a switch argument, the following named parameters are predefined:

  • action="store_const"

  • const=True

  • default=False

This implements a boolean parameter passed to the handler method.

_classes: List[Any] = []

List of classes, this pyAttribute was attached to.

CommonArgumentAttribute

class pyAttributes.ArgParseAttributes.CommonArgumentAttribute(*args, **kwargs)[source]

Bases: ArgumentAttribute

_classes: List[Any] = []

List of classes, this pyAttribute was attached to.

CommonSwitchArgumentAttribute

class pyAttributes.ArgParseAttributes.CommonSwitchArgumentAttribute(*args, dest, **kwargs)[source]

Bases: SwitchArgumentAttribute

_classes: List[Any] = []

List of classes, this pyAttribute was attached to.

See also

Base attribute class Attribute

Base-class for all attributes.

Helper mixin class AttributeHelperMixin

Base-class for all helper mixins.