Skip to content
Myr

Support non optional arguments on commands.

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

This relaxes the restriction from the last commit to allow required arguments with command groups again.

authored by Armin Ronacher · committed by Armin Ronacher · parent 1c7e1d3 · Browse files · 3 files+29 added−7 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+29 added−7 removed

  • tests:+25 added−3 removed
  • other:+4 added−4 removed

3 files+29 added−7 removed

modified:click/core.py+2 added-2 removed
927 unmodified lines
928 self.result_callback = result_callback929930 if self.chain:931 for param in self.params:932 if isinstance(param, Argument):932 if isinstance(param, Argument) and not param.required:933 raise RuntimeError('Multi commands in chain mode cannot '934 'have other arguments.')934 'have optional arguments.')935936 def collect_usage_pieces(self, ctx):937 rv = Command.collect_usage_pieces(self, ctx)938 rv.append(self.subcommand_metavar)
785 unmodified lines
modified:tests/test_chain.py+25 added-3 removed
187 unmodified lines
188 'c=',189 ]190191192def test_multicommand_no_args(runner):192def test_multicommand_arg_behavior(runner):193 with pytest.raises(RuntimeError):194 @click.group(chain=True)195 @click.argument('forbidden')196 def cli():195 @click.argument('forbidden', required=False)196 def bad_cli():197 pass198199 with pytest.raises(RuntimeError):200 @click.group(chain=True)201 @click.argument('forbidden', nargs=-1)202 def bad_cli2():203 pass204205 @click.group(chain=True)206 @click.argument('arg')207 def cli(arg):208 click.echo('cli:%s' % arg)209210 @cli.command()211 def a():212 click.echo('a')213214 result = runner.invoke(cli, ['foo', 'a'])215 assert not result.exception216 assert result.output.splitlines() == [217 'cli:foo',218 'a',219 ]
modified:CHANGES+2 added-2 removed
36 unmodified lines
37- Added support for allowing dashes to indicate standard streams to the38 `Path` type.39- Multi commands in chain mode no longer propagate arguments left over40 from parsing to the callbacks. It's also now disallowed through an41 exception that arguments are attached to multi commands if chain mode42 is enabled.41 exception when optional arguments are attached to multi commands if chain42 mode is enabled.4344Version 5.145-----------46
251 unmodified lines