diff options
Diffstat (limited to 'modules/language/python/module/optparse.py')
-rw-r--r-- | modules/language/python/module/optparse.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/modules/language/python/module/optparse.py b/modules/language/python/module/optparse.py index 886e685..903b374 100644 --- a/modules/language/python/module/optparse.py +++ b/modules/language/python/module/optparse.py @@ -210,12 +210,14 @@ class HelpFormatter: short_first): self.parser = None self.indent_increment = indent_increment + if width is None: try: width = int(os.environ['COLUMNS']) except (KeyError, ValueError): width = 80 width -= 2 + self.width = width self.help_position = self.max_help_position = \ min(max_help_position, max(width - 20, indent_increment * 2)) @@ -1102,7 +1104,6 @@ class OptionGroup (OptionContainer): formatter.dedent() return result - class OptionParser (OptionContainer): """ @@ -1186,17 +1187,23 @@ class OptionParser (OptionContainer): add_help_option=True, prog=None, epilog=None): + OptionContainer.__init__( self, option_class, conflict_handler, description) + self.set_usage(usage) self.prog = prog self.version = version self.allow_interspersed_args = True self.process_default_values = True + if formatter is None: formatter = IndentedHelpFormatter() + self.formatter = formatter + self.formatter.set_parser(self) + self.epilog = epilog # Populate the option list; initial sources are the @@ -1205,10 +1212,8 @@ class OptionParser (OptionContainer): # _add_help_option() methods. self._populate_option_list(option_list, add_help=add_help_option) - self._init_parsing_state() - def destroy(self): """ Declare that you are done with this OptionParser. This cleans up @@ -1307,14 +1312,12 @@ class OptionParser (OptionContainer): if not self.process_default_values: # Old, pre-Optik 1.5 behaviour. return Values(self.defaults) - defaults = self.defaults.copy() for option in self._get_all_options(): default = defaults.get(option.dest) if isinstance(default, str): opt_str = option.get_opt_string() defaults[option.dest] = option.check_value(opt_str, default) - return Values(defaults) @@ -1367,6 +1370,7 @@ class OptionParser (OptionContainer): over after parsing options. """ rargs = self._get_args(args) + if values is None: values = self.get_default_values() @@ -1434,7 +1438,7 @@ class OptionParser (OptionContainer): del rargs[0] else: return # stop now, leave this arg in rargs - + # Say this is the original argument list: # [arg0, arg1, ..., arg(i-1), arg(i), arg(i+1), ..., arg(N-1)] # ^ |