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:
MixIns¶
_HandlerMixin¶
_KwArgsMixin¶
_ArgsMixin¶
- class pyAttributes.ArgParseAttributes._ArgsMixin[source]¶
Bases:
_KwArgsMixin
A mixin-class that offers a class field for positional parameters (
`*args
) and a matching property.
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:
- 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.
- _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()
.
- _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 toadd_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 isTrue
if the switch argument is present in the commandline arguments, otherwiseFalse
.- __init__(*args, dest, **kwargs)[source]¶
The constructor expects positional (
*args
), the destination parameter namedest
and/or named parameters (**kwargs
) which are passed toadd_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.