Skip to content
Myr

Removed some dead code in optparse

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 8512acd · Browse files · 2 files+13 added−73 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−73 removed

  • other:+13 added−73 removed

2 files+13 added−73 removed

modified:click/_optparse.py+1 added-69 removed
110 unmodified lines
111 for opt in parser.option_list:112 strings = self.format_option_strings(opt)113 self.option_strings[opt] = strings114 max_len = max(max_len, len(strings) + self.current_indent)115 self.indent()116 for group in parser.option_groups:117 for opt in group.option_list:118 strings = self.format_option_strings(opt)119 self.option_strings[opt] = strings120 max_len = max(max_len, len(strings) + self.current_indent)115 self.dedent()122 self.dedent()116 self.help_position = min(max_len + 2, self.max_help_position)117 self.help_width = max(self.width - self.help_position, 11)118119 def format_option_strings(self, option):
165 unmodified lines
285 # OptionGroups that it owns.286 self._short_opt = {} # single letter -> Option instance287 self._long_opt = {} # long option -> Option instance288296 def _share_option_mappings(self, parser):297 # For use by OptionGroup constructor -- use shared option298 # mappings from the OptionParser that owns this OptionGroup.299 self._short_opt = parser._short_opt300 self._long_opt = parser._long_opt301289 def add_option(self, *args, **kwargs):290 if isinstance(args[0], str):291 option = self.option_class(*args, **kwargs)292 elif len(args) == 1 and not kwargs:
57 unmodified lines
350 result.append(self.format_option_help(formatter))351 return '\n'.join(result)352353367class OptionGroup(OptionContainer):368369 def __init__(self, parser, title, description=None):370 self.parser = parser371 OptionContainer.__init__(372 self, parser.option_class, description)373 self.title = title374375 def _create_option_list(self):376 self.option_list = []377 self._share_option_mappings(self.parser)378379 def set_title(self, title):380 self.title = title381382 def format_help(self, formatter):383 result = formatter.format_heading(self.title)384 formatter.indent()385 result += OptionContainer.format_help(self, formatter)386 formatter.dedent()387 return result388389354class OptionParser(OptionContainer):355 standard_option_list = []356357 def __init__(self,
18 unmodified lines
376 self._init_parsing_state()377378 def _create_option_list(self):379 self.option_list = []416 self.option_groups = []380 self._create_option_mappings()381382 def _populate_option_list(self, option_list):383 if self.standard_option_list:
5 unmodified lines
389 self.rargs = None390 self.largs = None391 self.values = None392430 def _get_all_options(self):431 options = self.option_list[:]432 for group in self.option_groups:433 options.extend(group.option_list)434 return options435436 def add_option_group(self, *args, **kwargs):437 if isinstance(args[0], str):438 group = OptionGroup(self, *args, **kwargs)439 elif len(args) == 1 and not kwargs:440 group = args[0]441 if not isinstance(group, OptionGroup):442 raise TypeError('not an OptionGroup instance: %r' % group)443 if group.parser is not self:444 raise ValueError('invalid OptionGroup (wrong parser)')445 else:446 raise TypeError('invalid arguments')447448 self.option_groups.append(group)449 return group450451 def get_option_group(self, opt_str):452 option = (self._short_opt.get(opt_str) or453 self._long_opt.get(opt_str))454 if option and option.container is not self:455 return option.container456 return None457393 def parse_args(self, args, values=None):394 rargs = args395 if values is None:396 values = {}
167 unmodified lines
564 formatter.indent()565 if self.option_list:566 result.append(OptionContainer.format_option_help(self, formatter))567 result.append('\n')633 for group in self.option_groups:634 result.append(group.format_help(formatter))635 result.append('\n')568 formatter.dedent()569 # Drop the last '\n', or the header if no options or option groups:570 return ''.join(result[:-1])571
59 unmodified lines
631 self.__ctx = ctx632633 def format_option_help(self, formatter):634 rv = OptionParser.format_option_help(self, formatter)703 extra_help = self.__ctx.command._format_extra_help(self.__ctx)635 extra_help = self.__ctx.command.format_extra_help(self.__ctx)636 if extra_help:637 rv = '%s\n%s' % (rv, extra_help)638 return rv639
2 unmodified lines
modified:click/core.py+12 added-4 removed
160 unmodified lines
161 def format_usage(self):162 """Helper method to get formatted usage string for the current163 context and command.164 """165 return self._parser.get_usage()165 return self.command.format_usage(self)166167 def format_help(self):168 """Helper method to get formatted help page for the current169 context and command.170 """171 return self._parser.format_help().rstrip()171 return self.command.format_help(self)172173 def invoke(*args, **kwargs):174 """Invokes a command callback in exactly the way it expects.175 """
102 unmodified lines
278 for param in self.params:279 param._add_to_parser(parser, ctx)280 return parser281282 def format_usage(self, ctx):283 """Formats the usage line."""284 return ctx._parser.get_usage()285286 def format_help(self, ctx):287 """Formats the help."""288 return ctx._parser.format_help().rstrip()289282 def _format_extra_help(self, ctx):290 def format_extra_help(self, ctx):291 pass292293 def make_context(self, info_name, args, parent=None, **extra):294 """This function when given an info name and arguments will kick
129 unmodified lines
424 parser.usage += ' ' + self.subcommand_metavar425 parser.allow_interspersed_args = False426 return parser427420 def _format_extra_help(self, ctx):428 def format_extra_help(self, ctx):429 commands = self.list_commands(ctx)430 if not commands:431 return432
520 unmodified lines