Skip to content
Myr

Restore the Click 1.0 help handling.

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 1cceb6d · Browse files · 2 files+30 added−5 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+30 added−5 removed

  • other:+30 added−5 removed

2 files+30 added−5 removed

modified:click/core.py+28 added-5 removed
629 unmodified lines
630 def parse_args(self, ctx, args):631 parser = self.make_parser(ctx)632 opts, args, param_order = parser.parse_args(args=args)633634 if opts.get('$help') and not ctx.resilient_parsing:635 echo(ctx.get_help())636 ctx.exit()634 # 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?649638 for param in iter_params_for_processing(param_order, self.params):639 value, args = param.handle_parse_result(ctx, opts, args)650 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()663664 if args and not self.allow_extra_args and not ctx.resilient_parsing:665 ctx.fail('Got unexpected extra argument%s (%s)'666 % (len(args) != 1 and 's' or '',667 ' '.join(map(make_str, args))))
687 unmodified lines
modified:CHANGES+2 added
9 unmodified lines
1011- Fixed an incorrectly formatted help record for count options.'12- Add support for ansi code stripping on Windows if colorama13 is not available.14- restored the Click 1.0 handling of the help parameter for certain15 edge cases.1617Version 2.218-----------19
78 unmodified lines