| |
- exceptions.Exception(exceptions.BaseException)
-
- util.ComLine.Error
-
- util.ComLine.DuplicateOptionError
- util.ComLine.UnknownOptionError
- util.ComLine.UsageError
- util.ComLine.ArgType
- util.ComLine.ComLine
class ArgType |
|
An instance of *ArgType* defines that characteristics of a single command
line option. All parameters to @__init__() are available as public
variables. |
|
Methods defined here:
- __init__(self, name, shortOptions, longOptions=[], parm=0, valid=None, mult=0, help='', helpCmd=0, parmHelp='parm')
- Constructs ArgType.
Parameters:
/name/::
Name of the option.
/shortOptions/::
A string containing the single character command line options.
/longOptions/::
A list of strings containing the long (full word) command line
options.
/parm/::
If this is true, the argument accepts a parameter.
/valid/::
If used, should be passed a function which accepts the value of the
argument and returns true if the argument is valid (falls within
the constraints defined by the parameter). Only appropriate in
conjunction with /parm/
/mult/::
If this is true, the argument may be used more than once on the
command line and its value will be returned as a list of all of
the values that have been defined for it.
/help/::
If set, this contains a help message that will be printed out along
with the option when help is displayed using @ComLine.help()
/helpCmd/::
If this is true, the use of this option automatically triggers the
@ComLine.help() function.
/parmHelp/::
This is the string that will be printed in the option's help message
in to describe the parameter for the option. For example, if a value
of "file-name" is used for a "-c" option, the option help will look
like this:
{{
-c <file-name>
Does something with the given file.
}}
|
class ComLine |
|
Instances of this class parse and manage command line options.
The public variable /args/ is an array containing the unprocessed
command line arguments (those that did not begin with '-'). |
|
Methods defined here:
- __getitem__(self, key)
- Attempts to make the command line accessible as both an array and a
dictionary. If /key/ is an integer, returns a tuple containing either
the indexed argument and *None* (if it is a non-option argument) or
the value of the option and the @ArgType object for the option (if it
is a command line option).
If /key/ is a string, it should be the name of a command line option and
the value of that option will be returned. This will return *None* if
the option is a legitimate option but was not specified on the command
line.
If the value specified by the key does not exist, raises either an
*IndexError* or a *KeyError* depending on the mode of addressing used.
- __init__(self, arginfo, argv=None, helpPrefix=None)
- Constructs a ComLine object from /arginfo/ (a list of @ArgType instances)
and /argv/ (list of command line arguments). If argv is not supplied,
sys.argv is used.
- help(self)
- Prints out a nicely formatted help message containing a description of
each of the options. If /helpPrefix/ was supplied during construction,
prints this first. Otherwise, just prints the program name first.
- optionsHelpToNML(self, cleanHelpText=0)
- Returns a string representing the options help formatted in NML.
If /cleanHelpText/ is true, escapes the special NML characters
in the help text.
- others(self)
- Constructs and returns a list of all non-option parameters.
|
|