| | |
- exceptions.Exception
-
- OptParseError
-
- BadOptionError
- OptionError
-
- OptionConflictError
- OptionValueError
- HelpFormatter
-
- IndentedHelpFormatter
- TitledHelpFormatter
- Option
- OptionContainer
-
- OptionGroup
- OptionParser
- Values
class HelpFormatter |
| |
Abstract base class for formatting option help. OptionParser
instances should use one of the HelpFormatter subclasses for
formatting help; by default IndentedHelpFormatter is used.
Instance attributes:
indent_increment : int
the number of columns to indent per nesting level
max_help_position : int
the maximum starting column for option help text
help_position : int
the calculated starting column for option help text;
initially the same as the maximum
width : int
total number of columns for output
level : int
current indentation level
current_indent : int
current indentation level (in columns)
help_width : int
number of columns available for option help text (calculated) |
| |
Methods defined here:
- __init__(self, indent_increment, max_help_position, width, short_first)
- dedent(self)
- format_description(self, description)
- format_heading(self, heading)
- format_option(self, option)
- format_option_strings(self, option)
- Return a comma-separated list of option strings & metavariables.
- format_usage(self, usage)
- indent(self)
- store_option_strings(self, parser)
|
class IndentedHelpFormatter(HelpFormatter) |
| |
Format help with indented section bodies. |
| |
Methods defined here:
- __init__(self, indent_increment=2, max_help_position=24, width=80, short_first=1)
- format_heading(self, heading)
- format_usage(self, usage)
Methods inherited from HelpFormatter:
- dedent(self)
- format_description(self, description)
- format_option(self, option)
- format_option_strings(self, option)
- Return a comma-separated list of option strings & metavariables.
- indent(self)
- store_option_strings(self, parser)
|
class Option |
| |
Instance attributes:
_short_opts : [string]
_long_opts : [string]
action : string
type : string
dest : string
default : any
nargs : int
const : any
choices : [string]
callback : function
callback_args : (any*)
callback_kwargs : { string : any }
help : string
metavar : string |
| |
Methods defined here:
- __init__(self, *opts, **attrs)
- __str__(self)
- check_value(self, opt, value)
- process(self, opt, value, values, parser)
- take_action(self, action, dest, opt, value, values, parser)
- takes_value(self)
Data and other attributes defined here:
- ACTIONS = ('store', 'store_const', 'store_true', 'store_false', 'append', 'count', 'callback', 'help', 'version')
- ATTRS = ['action', 'type', 'dest', 'default', 'nargs', 'const', 'choices', 'callback', 'callback_args', 'callback_kwargs', 'help', 'metavar']
- CHECK_METHODS = [<function _check_action>, <function _check_type>, <function _check_choice>, <function _check_dest>, <function _check_const>, <function _check_nargs>, <function _check_callback>]
- STORE_ACTIONS = ('store', 'store_const', 'store_true', 'store_false', 'append', 'count')
- TYPED_ACTIONS = ('store', 'append', 'callback')
- TYPES = ('string', 'int', 'long', 'float', 'complex', 'choice')
- TYPE_CHECKER = {'choice': <function check_choice>, 'complex': <function check_builtin>, 'float': <function check_builtin>, 'int': <function check_builtin>, 'long': <function check_builtin>}
|
class OptionContainer |
| |
Abstract base class.
Class attributes:
standard_option_list : [Option]
list of standard options that will be accepted by all instances
of this parser class (intended to be overridden by subclasses).
Instance attributes:
option_list : [Option]
the list of Option objects contained by this OptionContainer
_short_opt : { string : Option }
dictionary mapping short option strings, eg. "-f" or "-X",
to the Option instances that implement them. If an Option
has multiple short option strings, it will appears in this
dictionary multiple times. [1]
_long_opt : { string : Option }
dictionary mapping long option strings, eg. "--file" or
"--exclude", to the Option instances that implement them.
Again, a given Option can occur multiple times in this
dictionary. [1]
defaults : { string : any }
dictionary mapping option destination names to default
values for each destination [1]
[1] These mappings are common to (shared by) all components of the
controlling OptionParser, where they are initially created. |
| |
Methods defined here:
- __init__(self, option_class, conflict_handler, description)
- add_option(self, *args, **kwargs)
- add_option(Option)
add_option(opt_str, ..., kwarg=val, ...)
- add_options(self, option_list)
- format_description(self, formatter)
- format_help(self, formatter)
- format_option_help(self, formatter)
- get_option(self, opt_str)
- has_option(self, opt_str)
- remove_option(self, opt_str)
- set_conflict_handler(self, handler)
- set_description(self, description)
|
class OptionGroup(OptionContainer) |
| | |
Methods defined here:
- __init__(self, parser, title, description=None)
- format_help(self, formatter)
- set_title(self, title)
Methods inherited from OptionContainer:
- add_option(self, *args, **kwargs)
- add_option(Option)
add_option(opt_str, ..., kwarg=val, ...)
- add_options(self, option_list)
- format_description(self, formatter)
- format_option_help(self, formatter)
- get_option(self, opt_str)
- has_option(self, opt_str)
- remove_option(self, opt_str)
- set_conflict_handler(self, handler)
- set_description(self, description)
|
class OptionParser(OptionContainer) |
| |
Class attributes:
standard_option_list : [Option]
list of standard options that will be accepted by all instances
of this parser class (intended to be overridden by subclasses).
Instance attributes:
usage : string
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[0])).
prog : string
the name of the current program (to override
os.path.basename(sys.argv[0])).
allow_interspersed_args : boolean = 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.)
rargs : [string]
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
callback options.
largs : [string]
the list of leftover arguments that we have skipped while
parsing options. If allow_interspersed_args is false, this
list is always empty.
values : Values
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. |
| |
Methods defined here:
- __init__(self, usage=None, option_list=None, option_class=<class optparse.Option>, version=None, conflict_handler='error', description=None, formatter=None, add_help_option=1, prog=None)
- add_option_group(self, *args, **kwargs)
- check_values(self, values, args)
- check_values(values : Values, args : [string])
-> (values : Values, args : [string])
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.
- disable_interspersed_args(self)
- enable_interspersed_args(self)
- error(self, msg)
- error(msg : string)
Print a usage message incorporating 'msg' to stderr and exit.
If you override this in a subclass, it should not return -- it
should either exit or raise an exception.
- format_help(self, formatter=None)
- format_option_help(self, formatter=None)
- get_default_values(self)
- get_option_group(self, opt_str)
- get_usage(self)
- get_version(self)
- parse_args(self, args=None, values=None)
- parse_args(args : [string] = sys.argv[1:],
values : Values = None)
-> (values : Values, args : [string])
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_help(self, file=None)
- print_help(file : file = stdout)
Print an extended help message, listing all options and any
help text provided with them, to 'file' (default stdout).
- print_usage(self, file=None)
- print_usage(file : file = stdout)
Print the usage message for the current program (self.usage) to
'file' (default stdout). Any occurence of the string "%prog" in
self.usage is replaced with the name of the current program
(basename of sys.argv[0]). Does nothing if self.usage is empty
or not defined.
- print_version(self, file=None)
- print_version(file : file = stdout)
Print the version message for this program (self.version) to
'file' (default stdout). As with print_usage(), any occurence
of "%prog" in self.version is replaced by the current program's
name. Does nothing if self.version is empty or undefined.
- set_default(self, dest, value)
- set_defaults(self, **kwargs)
- set_usage(self, usage)
Data and other attributes defined here:
- standard_option_list = []
Methods inherited from OptionContainer:
- add_option(self, *args, **kwargs)
- add_option(Option)
add_option(opt_str, ..., kwarg=val, ...)
- add_options(self, option_list)
- format_description(self, formatter)
- get_option(self, opt_str)
- has_option(self, opt_str)
- remove_option(self, opt_str)
- set_conflict_handler(self, handler)
- set_description(self, description)
|
class TitledHelpFormatter(HelpFormatter) |
| |
Format help with underlined section headers. |
| |
Methods defined here:
- __init__(self, indent_increment=0, max_help_position=24, width=80, short_first=0)
- format_heading(self, heading)
- format_usage(self, usage)
Methods inherited from HelpFormatter:
- dedent(self)
- format_description(self, description)
- format_option(self, option)
- format_option_strings(self, option)
- Return a comma-separated list of option strings & metavariables.
- indent(self)
- store_option_strings(self, parser)
|
make_option = class Option |
| |
Instance attributes:
_short_opts : [string]
_long_opts : [string]
action : string
type : string
dest : string
default : any
nargs : int
const : any
choices : [string]
callback : function
callback_args : (any*)
callback_kwargs : { string : any }
help : string
metavar : string |
| |
Methods defined here:
- __init__(self, *opts, **attrs)
- __str__(self)
- check_value(self, opt, value)
- process(self, opt, value, values, parser)
- take_action(self, action, dest, opt, value, values, parser)
- takes_value(self)
Data and other attributes defined here:
- ACTIONS = ('store', 'store_const', 'store_true', 'store_false', 'append', 'count', 'callback', 'help', 'version')
- ATTRS = ['action', 'type', 'dest', 'default', 'nargs', 'const', 'choices', 'callback', 'callback_args', 'callback_kwargs', 'help', 'metavar']
- CHECK_METHODS = [<function _check_action>, <function _check_type>, <function _check_choice>, <function _check_dest>, <function _check_const>, <function _check_nargs>, <function _check_callback>]
- STORE_ACTIONS = ('store', 'store_const', 'store_true', 'store_false', 'append', 'count')
- TYPED_ACTIONS = ('store', 'append', 'callback')
- TYPES = ('string', 'int', 'long', 'float', 'complex', 'choice')
- TYPE_CHECKER = {'choice': <function check_choice>, 'complex': <function check_builtin>, 'float': <function check_builtin>, 'int': <function check_builtin>, 'long': <function check_builtin>}
| |