Skip to content
Myr

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

4 files+29 added−20 removed

modified:click/core.py+24 added
35 unmodified lines
36 if bashcomplete(cmd, prog_name, complete_var, complete_instr):37 sys.exit(1)383940def _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))596061def batch(iterable, batch_size):62 return list(zip(*repeat(iter(iterable), batch_size)))6364
1078 unmodified lines
1143 """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] = cmd11491150 def command(self, *args, **kwargs):1151 """A shortcut decorator for declaring and attaching a command to
45 unmodified lines
1197 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 rv12041205 def list_commands(self, ctx):1206 rv = set()
532 unmodified lines
modified:docs/commands.rst+3 added-20 removed
319 unmodified lines
320one command is invoked. This is necessary because the handling of321subcommands happens one after another so the exact subcommands that will322be handled are not yet available when the callback fires.323324.. note::325325Nested 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.328328.. versionadded:: 6.0329330Before Click 6 it was not possible for chain commands to be nested as331behavior was not entirely defined. In Click 6 this has been corrected332and group commands can now be nested below chain commands. The following333logic applies as a result:334335* 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.345346330Multi Command Pipelines331-----------------------332333.. versionadded:: 3.0
225 unmodified lines
modified:tests/test_chain.py+1 added
218 unmodified lines
219 'a',220 ]221222223@pytest.mark.xfail224def test_multicommand_chaining(runner):225 @click.group(chain=True)226 def cli():227 debug()
25 unmodified lines
modified:CHANGES+1 added
7 unmodified lines
89(bugfix release, release date to be decided)1011- Resolved an issue with invisible progress bars no longer rendering.12- Disable chain commands with subcommands as they were inherently broken.1314Version 6.015-----------16
291 unmodified lines