Disable chain commands
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 b47b117 · Browse files · 4 files·+29 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+29 added−20 removed
- tests:+1 added−0 removed
- other:+28 added−20 removed
Provenance
- Commit
cc6fec2- Tree
6369d4f- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
b47b117
4 files changed+29 added−20 removed
modified:click/core.py+24 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"). This restriction was supposed to '53+ 'be lifted in 6.0 but the fix was flawed. This '54+ 'will be fixed in Click 7.0' % (55+ hint, base_command.name, cmd_name,56+ cmd_name, cmd.__class__.__name__,57+ base_command.__class__.__name__,58+ base_command.name))59+60+61 def batch(iterable, batch_size):62 return list(zip(*repeat(iter(iterable), batch_size)))63 64 1078 unmodified lines1143 """1144 name = name or cmd.name1145 if name is None:1146 raise TypeError('Command has no name.')1147+ _check_multicommand(self, name, cmd, register=True)1148 self.commands[name] = cmd1149 1150 def command(self, *args, **kwargs):1151 """A shortcut decorator for declaring and attaching a command to45 unmodified lines1197 def get_command(self, ctx, cmd_name):1198 for source in self.sources:1199 rv = source.get_command(ctx, cmd_name)1200 if rv is not None:1201+ if self.chain:1202+ _check_multicommand(self, cmd_name, rv)1203 return rv1204 1205 def list_commands(self, ctx):1206 rv = set()532 unmodified linesmodified:docs/commands.rst+3 added-20 removed
319 unmodified lines320 one command is invoked. This is necessary because the handling of321 subcommands happens one after another so the exact subcommands that will322 be handled are not yet available when the callback fires.323 324+.. note::325 325-Nested Group Commands with Chaining326------------------------------------326+ It is currently not possible for chain commands to be nested. This327+ will be fixed in future versions of Click.328 328-.. versionadded:: 6.0329 330-Before Click 6 it was not possible for chain commands to be nested as331-behavior was not entirely defined. In Click 6 this has been corrected332-and group commands can now be nested below chain commands. The following333-logic applies as a result:334-335-* if a chain command is used below a chain command it will not be336- possible for the outer command to accept any more arguments with the337- start of the sub command. This is done in order to ensure that338- commands do not change behavior when nested below other commands.339-* Click now internally has the concept of protected arguments which is340- what is used to ensure nested parsing does not accidentally mix341- rest arguments intended for the callbacks with leftover arguments for342- parsing. This change has cleaned up some accidental bugs in the past343- where the context showed arguments that were not actually intended for344- the command.345-346-330 Multi Command Pipelines331 -----------------------332 333 .. versionadded:: 3.0225 unmodified linesmodified:tests/test_chain.py+1 added
218 unmodified lines219 'a',220 ]221 222 223+@pytest.mark.xfail224 def test_multicommand_chaining(runner):225 @click.group(chain=True)226 def cli():227 debug()25 unmodified linesmodified:CHANGES+1 added
7 unmodified lines8 9 (bugfix release, release date to be decided)10 11 - Resolved an issue with invisible progress bars no longer rendering.12+- Disable chain commands with subcommands as they were inherently broken.13 14 Version 6.015 -----------16 291 unmodified lines