This content refers to an unreleased development version of PyMVPA
To provide the most recent news and documentation www.pymvpa.org reflects the
development 2.0 series (renamed 0.6 series) of PyMVPA. If you are interested in the
documentation of the previous stable 0.4 series of PyMVPA, please
class mvpa2.misc.cmdline.OptionParser(usage=None, option_list=None, option_class=<class optparse.Option at 0x8f57bcc>, version=None, conflict_handler='error', description=None, formatter=None, add_help_option=True, prog=None, epilog=None)¶
list of standard options that will be accepted by all instances
of this parser class (intended to be overridden by subclasses).
a usage string for your program. Before it is displayed
to the user, “%prog” will be expanded to the name of
your program (self.prog or os.path.basename(sys.argv)).
the name of the current program (to override
A paragraph of text giving a brief overview of your program.
optparse reformats this paragraph to fit the current terminal
width and prints it when the user requests help (after usage,
but before the list of options).
paragraph of help text to print after option help
list of option groups in this parser (option groups are
irrelevant for parsing the command-line, but very useful
for generating help)
allow_interspersed_args :bool = true
if true, positional arguments may be interspersed with options.
Assuming -a and -b each take a single argument, the command-line
-ablah foo bar -bboo baz
will be interpreted the same as
-ablah -bboo – foo bar baz
If this flag were false, that command line would be interpreted as
-ablah – foo bar -bboo baz
– ie. we stop processing options as soon as we see the first
non-option argument. (This is the tradition followed by
Python’s getopt module, Perl’s Getopt::Std, and other argument-
parsing libraries, but it is generally annoying to users.)
process_default_values :bool = true
if true, option default values are processed similarly to option
values from the command line: that is, they are passed to the
type-checking function for the option’s type (as long as the
default value is a string). (This really only matters if you
have defined custom types; see SF bug #955889.) Set it to false
to restore the behaviour of Optik 1.4.1 and earlier.
the argument list currently being parsed. Only set when
parse_args() is active, and continually trimmed down as
we consume arguments. Mainly there for the benefit of
the list of leftover arguments that we have skipped while
parsing options. If allow_interspersed_args is false, this
list is always empty.
the set of option values currently being accumulated. Only
set when parse_args() is active. Also mainly for callbacks.
Because of the ‘rargs’, ‘largs’, and ‘values’ attributes,
OptionParser is not thread-safe. If, for some perverse reason, you
need to parse command-line arguments simultaneously in different
threads, use different OptionParser instances.
Check that the supplied option values and leftover arguments are
valid. Returns the option values and leftover arguments
(possibly adjusted, possibly completely new – whatever you
like). Default implementation just returns the passed-in
values; subclasses may override as desired.
Declare that you are done with this OptionParser. This cleans up
reference cycles so the OptionParser (and all objects referenced by
it) can be garbage-collected promptly. After calling destroy(), the
OptionParser is unusable.
Set parsing to not stop on the first non-option, allowing
interspersing switches with command arguments. This is the
default behavior. See also disable_interspersed_args() and the
class documentation description of the attribute
Parse the command-line options found in ‘args’ (default:
sys.argv[1:]). Any errors result in a call to ‘error()’, which
by default prints the usage message to stderr and calls
sys.exit() with an error message. On success returns a pair
(values, args) where ‘values’ is an Values instance (with all
your option values) and ‘args’ is the list of arguments left
over after parsing options.
Print the usage message for the current program (self.usage) to
‘file’ (default stdout). Any occurrence of the string “%prog” in
self.usage is replaced with the name of the current program
(basename of sys.argv). Does nothing if self.usage is empty
or not defined.
Print the version message for this program (self.version) to
‘file’ (default stdout). As with print_usage(), any occurrence
of “%prog” in self.version is replaced by the current program’s
name. Does nothing if self.version is empty or undefined.