add_param(self,
name,
ptype,
mandatory=False,
attrname=None,
defval=None,
admvals=None,
multival=False,
seplist=False,
metavar=None,
desc=None)
|
|
Define a parameter.
A parameter is at minimum defined by its name and value type, and may
be optional or mandatory. Optional parameter will be set to the supplied
default value if not encountered during parsing.
Default value must be of the given parameter type (in the sense of
isinstance() ) or None . Default value of
None can be used to be able to check if the parameter has
been parsed at all. If parameter type is boolean, then the default value
has a special meaning: the parameter is always parsed without an argument
(a flag), and its value will become negation of the default value. If
parameter value is not arbitrary for the given type, the set of
admissible values can be defined too.
Parameter can be used to collect a list of values, in two ways, or
both combined. One is by repeating the parameter several times with
different values, and another by a single parameter value itself being a
comma-separated list of values (in which case the values are parsed into
elements of requested type). For such parameters the default value should
be a list too (or None ).
For help purposes, parameter may be given a description and
metavariable to represent its value.
If the parameter being added to current subcommand has the name same
as a previously defined parameter to another subcommand, then the current
parameter shares semantics with the old one. This means that the type and
list nature of current parameter must match that of the previous one
(i.e. ptype , multival , and seplist
must have same values).
Double-newline in description string splits text into paragraphs.
- Parameters:
name (string) - parameter name
ptype (type) - type of the expected argument
mandatory (bool) - whether parameter is mandatory
attrname (string) - explicit name for the object attribute under which the parsed
parameter value is stored (auto-derived if None )
defval (instance of ptype or None ) - default value for the argument
admvals (list of ptype elements or None ) - admissible values for the argument
multival (bool) - whether parameter can be repeated for list of values
seplist (bool) - whether parameter is a comma-separated list of values
metavar (string or None ) - name for parameter's value
desc (string or None ) - description of the parameter
|