Skip to content
Myr

Merge branch '2.x-maintenance'

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 · parents 4ee540d, 73ef9f3 · Browse files · 2 files+35 added−45 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+35 added−45 removed

  • other:+35 added−45 removed

2 files+35 added−45 removed

modified:click/core.py+28 added-45 removed
534 unmodified lines
535 formatter = ctx.make_formatter()536 self.format_usage(ctx, formatter)537 return formatter.getvalue().rstrip('\n')538539 def get_params(self, ctx):540 rv = self.params541 help_option = self.get_help_option(ctx)542 if help_option is not None:543 rv = rv + [help_option]544 return rv545546 def format_usage(self, ctx, formatter):547 """Writes the usage line into the formatter."""548 pieces = self.collect_usage_pieces(ctx)549 formatter.write_usage(ctx.command_path, ' '.join(pieces))
2 unmodified lines
552 """Returns all the pieces that go into the usage line and returns553 it as a list of strings.554 """555 rv = [self.options_metavar]549 for param in self.params:556 for param in self.get_params(ctx):557 rv.extend(param.get_usage_pieces(ctx))558 return rv559560 def get_help_option_names(self, ctx):
3 unmodified lines
564 all_names.difference_update(param.opts)565 all_names.difference_update(param.secondary_opts)566 return all_names567568 def get_help_option(self, ctx):569 """Returns the help option object."""570 help_options = self.get_help_option_names(ctx)571 if not help_options:572 return573574 def show_help(ctx, param, value):575 if value and not ctx.resilient_parsing:576 echo(ctx.get_help())577 ctx.exit()578 return Option(help_options, is_flag=True,579 is_eager=True, expose_value=False,580 callback=show_help,581 help='Show this message and exit.')582583 def make_parser(self, ctx):584 """Creates the underlying option parser for this command."""585 parser = OptionParser(ctx)564 for param in self.params:586 for param in self.get_params(ctx):587 param.add_to_parser(parser, ctx)566567 if self.add_help_option:568 help_options = self.get_help_option_names(ctx)569 if help_options:570 parser.add_option(help_options, action='store_const',571 const=True, dest='$help')572588 return parser589590 def get_help(self, ctx):591 """Formats the help into a string and returns it. This creates a
27 unmodified lines
619620 def format_options(self, ctx, formatter):621 """Writes all the options into the formatter if they exist."""622 opts = []608 for param in self.params:623 for param in self.get_params(ctx):624 rv = param.get_help_record(ctx)625 if rv is not None:626 opts.append(rv)627613 if self.add_help_option:614 help_options = self.get_help_option_names(ctx)615 if help_options:616 opts.append([join_options(help_options)[0],617 'Show this message and exit.'])618628 if opts:629 with formatter.section('Options'):630 formatter.write_dl(opts)631
7 unmodified lines
639 def parse_args(self, ctx, args):640 parser = self.make_parser(ctx)641 opts, args, param_order = parser.parse_args(args=args)642634 # XXX: this logic requires a bit of explanation. As a change in635 # 2.x we accidentally broke a pattern used in 1.x which was636 # to customize the commands by passing more arguments. Because637 # the help option however was moved away from regular handling638 # to the front it meant that other arguments can no longer be639 # handled at all. The workaround for 2.x is that we try this:640 #641 # 1. start with regular handling. If a click exception happens642 # we show the help instead if wanted.643 # 2. if every callback went through we try to show the help now.644 #645 # This restores the old behavior in practical terms while still646 # special casing the help.647 #648 # Maybe this should be done differently?643 for param in iter_params_for_processing(644 param_order, self.get_params(ctx)):645 value, args = param.handle_parse_result(ctx, opts, args)646650 def _try_show_help():651 if opts.get('$help') and not ctx.resilient_parsing:652 echo(ctx.get_help())653 ctx.exit()654655 try:656 for param in iter_params_for_processing(param_order, self.params):657 value, args = param.handle_parse_result(ctx, opts, args)658 except ClickException:659 _try_show_help()660 raise661 else:662 _try_show_help()663647 if args and not self.allow_extra_args and not ctx.resilient_parsing:648 ctx.fail('Got unexpected extra argument%s (%s)'649 % (len(args) != 1 and 's' or '',650 ' '.join(map(make_str, args))))
692 unmodified lines
modified:CHANGES+7 added
20 unmodified lines
21 now, Click will give an error message instead of silently22 passing. This should catch situations where users wanted to23 created arguments instead of options.2425Version 2.426-----------2728(bugfix release, released on July 4th 2014)2930- Corrected a bug in the change of the help option in 2.3.3132Version 2.333-----------3435(bugfix release, released on July 3rd 2014)
88 unmodified lines