Skip to content
Myr

Added support for requiring with multiples.

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 5dbdfef · Browse files · 2 files+23 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

2 files+23 added−1 removed

  • tests:+15 added−0 removed
  • other:+8 added−1 removed

2 files+23 added−1 removed

modified:click/core.py+8 added-1 removed
740 unmodified lines
741 return self.type(value, self, ctx)742 return tuple(_convert(x, level - 1) for x in value or ())743 return _convert(value, (self.nargs != 1) + bool(self.multiple))744745 def value_is_missing(self, value):746 if value is None:747 return True748 if (self.nargs != 1 or self.multiple) and value == ():749 return True750 return False751752 def full_process_value(self, ctx, value):753 value = self.process_value(ctx, value)754755 if value is None:756 value = self.get_default(ctx)757751 if value is None and self.required:758 if self.required and self.value_is_missing(value):759 ctx.fail(self.get_missing_message(ctx))760761 return value762
313 unmodified lines
modified:tests/test_options.py+15 added
32 unmodified lines
33 result = runner.invoke(cli, ['-vvvv'])34 assert result.exception35 assert 'Invalid value for "-v": 4 is not in the valid range of 0 to 3.' \36 in result.output373839def test_multiple_required(runner):40 @click.command()41 @click.option('-m', '--message', multiple=True, required=True)42 def cli(message):43 click.echo('\n'.join(message))4445 result = runner.invoke(cli, ['-m', 'foo', '-mbar'])46 assert not result.exception47 assert result.output == 'foo\nbar\n'4849 result = runner.invoke(cli, [])50 assert result.exception51 assert 'Error: Missing option "-m" / "--message".' in result.output