Package pology :: Module subcmd :: Class SubcmdView

Class SubcmdView

object --+
         |
        SubcmdView

The view of a particular subcommand in a parameter parser.

Instance Methods
 
__init__(self, parent, subcmd, desc=None, shdesc=None)
Constructor.
 
set_desc(self, desc)
Set description of the subcommand.
 
set_shdesc(self, shdesc)
Set short description of the subcommand.
 
add_param(self, name, ptype, mandatory=False, attrname=None, defval=None, admvals=None, multival=False, seplist=False, metavar=None, desc=None)
Define a parameter.
string
help(self, wcol=None, stream=sys.stdout)
Formatted help for the subcommand.
string
name(self)
Get subcommand name.
string
shdesc(self)
Get short description of the subcommand.
[string]
params(self, addcol=False)
Get the list of subcommand parameters.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, parent, subcmd, desc=None, shdesc=None)
(Constructor)

 

Constructor.

Parameters:
  • parent (ParamParser) - the parent parameter parser.
  • subcmd (string) - subcommand name
  • desc (string) - subcommand description
  • shdesc (string) - short subcommand description
Overrides: object.__init__

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

help(self, wcol=None, stream=sys.stdout)

 

Formatted help for the subcommand.

Parameters:
  • wcol (int) - column to wrap text at (<= 0 for no wrapping, None for automatic according to output stream)
  • stream (file) - intended output stream for the text
Returns: string
formatted help

name(self)

 

Get subcommand name.

Returns: string
subcommand name

shdesc(self)

 

Get short description of the subcommand.

Short description was either explicitly provided on construction, or it is taken as the first sentence of the first paragraph of the full description.

Returns: string
short description

params(self, addcol=False)

 

Get the list of subcommand parameters.

Parameters:
  • addcol (bool) - append colon (:) to non-flag parameters
Returns: [string]
list of subcommand parameters