We're not rejecting multi commands below chained multi commands. This fixes #415
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 c4c9eb2 · Browse files · 3 files·+27 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+27 added−1 removed
- other:+27 added−1 removed
Provenance
- Commit
5620b05- Tree
7ae5809- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
c4c9eb2
3 files changed+27 added−1 removed
modified:click/core.py+22 added
35 unmodified lines36 if bashcomplete(cmd, prog_name, complete_var, complete_instr):37 sys.exit(1)38 39 40+def _check_multicommand(base_command, cmd_name, cmd, register=False):41+ if not base_command.chain or not isinstance(cmd, MultiCommand):42+ return43+ if register:44+ hint = 'It is not possible to add multi commands as children to ' \45+ 'another multi command that is in chain mode'46+ else:47+ hint = 'Found a multi command as subcommand to a multi command ' \48+ 'that is in chain mode. This is not supported'49+ raise RuntimeError('%s. Command "%s" is set to chain and "%s" was '50+ 'added as subcommand but it in itself is a '51+ 'multi command. ("%s" is a %s within a chained '52+ '%s named "%s")' % (53+ hint, base_command.name, cmd_name,54+ cmd_name, cmd.__class__.__name__,55+ base_command.__class__.__name__,56+ base_command.name))57+58+59 def batch(iterable, batch_size):60 return list(zip(*repeat(iter(iterable), batch_size)))61 62 1066 unmodified lines1129 """1130 name = name or cmd.name1131 if name is None:1132 raise TypeError('Command has no name.')1133+ _check_multicommand(self, name, cmd, register=True)1134 self.commands[name] = cmd1135 1136 def command(self, *args, **kwargs):1137 """A shortcut decorator for declaring and attaching a command to44 unmodified lines1182 1183 def get_command(self, ctx, cmd_name):1184 for source in self.sources:1185 rv = source.get_command(ctx, cmd_name)1186+ if self.chain:1187+ _check_multicommand(self, cmd_name, rv)1188 if rv is not None:1189 return rv1190 1191 def list_commands(self, ctx):527 unmodified linesmodified:docs/commands.rst+2 added-1 removed
308 unmodified lines309 310 invoke(cli, prog_name='setup.py', args=['sdist', 'bdist_wheel'])311 312 When using multi command chaining you can only have one command (the last)313-use ``nargs=-1`` on an argument. Other than that there are no313+use ``nargs=-1`` on an argument. It is also not possible to nest multi314+commands below chained multicommands. Other than that there are no315 restrictions on how they work. They can accept options and arguments as316 normal.317 318 Another note: the :attr:`Context.invoked_subcommand` attribute is a bit235 unmodified linesmodified:CHANGES+3 added
8 unmodified lines9 (codename and release date to be decided)10 11 - Optimized the progressbar rendering to not render when it did not12 actually change.13+- Actively reject multi commands within chained multi commands. This14+ cannot be supported with the current setup of how the invocation for15+ subcommands works.16 17 Version 5.118 -----------19 251 unmodified lines