Skip to content
Myr

Changed how sub commands are invoked and made it clearer.

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 e2124ba · Browse files · 1 file+9 added−11 removed
This commit

State

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

Diff stats

1 file+9 added−11 removed

  • other:+9 added−11 removed

1 file+9 added−11 removed

modified:click/core.py+9 added-11 removed
124 unmodified lines
125126 def find_object(self, object_type):127 """Finds the closest object of a given type."""128 node = self129 while node.parent is not None:129 while node is not None:130 if isinstance(node.obj, object_type):131 return node.obj132 node = node.parent133
76 unmodified lines
210 short_help = help.split('.')[0].strip()211 if len(short_help) > 45:212 short_help = None213 elif short_help:214 short_help = short_help[0].lower() + short_help[1:] + '.'214 short_help = short_help + '.'215 self.short_help = short_help216 if add_help_option:217 help_option()(self)218
153 unmodified lines
372 subcommand_info.append(' %-*s %s' % (longest, subcommand, help))373374 return 'Commands:\n%s' % '\n'.join(subcommand_info)375376 def make_context(self, info_name, args, parent=None, **extra):377 # Multi-commands invoked without any arguments is a shortcut to378 # invoking it with --help unless supresssed.379 if not args and self.no_args_is_help:380 args = ['--help']381 return Command.make_context(self, info_name, args, parent, **extra)382376 def invoke(self, ctx):377 if not ctx.args:378 if self.invoke_without_command:379 return Command.invoke(self, ctx)380 elif self.no_args_is_help:381 echo(ctx.format_help())382 ctx.exit()383 ctx.fail('Missing command')388 cmd_name = ctx.args[0]384385 cmd_name = ctx.args[0]386 cmd = self.get_command(ctx, cmd_name)387 if cmd is None:388 ctx.fail('No such command "%s"' % cmd_name)389 return self.invoke_subcommand(ctx, cmd, cmd_name, ctx.args[1:])390391 def invoke_subcommand(self, ctx, cmd, cmd_name, args):392 # Whenever we dispatch to a subcommand we also invoke the regular393 # callback. This is done so that parameters can be handled.394 ctx.invoked_subcommand = cmd_name395 Command.invoke(self, ctx)396399 with cmd.make_context(cmd_name, ctx.args[1:], parent=ctx) as cmd_ctx:397 with cmd.make_context(cmd_name, args, parent=ctx) as cmd_ctx:398 return cmd.invoke(cmd_ctx)399400 def get_command(self, ctx, cmd_name):401 """Given a context and a command name, this returns a
452 unmodified lines