Skip to content
Myr

Customize required in arguments for nargs of -1

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 247f9a3 · Browse files · 3 files+30 added−4 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+30 added−4 removed

  • tests:+10 added−1 removed
  • other:+20 added−3 removed

3 files+30 added−4 removed

modified:click/core.py+3 added-1 removed
1166 unmodified lines
1167 All parameters are passed onwards to the parameter constructor.1168 """1169 param_type_name = 'argument'11701171 def __init__(self, param_decls, required=True, **attrs):1171 def __init__(self, param_decls, required=None, **attrs):1172 if required is None:1173 required = attrs.get('nargs', 0) > 01174 Parameter.__init__(self, param_decls, required=required, **attrs)11751176 def make_metavar(self):1177 if self.metavar is not None:
31 unmodified lines
modified:examples/repo/repo.py+17 added-2 removed
102 unmodified lines
103 click.echo('Changed credentials.')104105106@cli.command()107@click.option('--message', '-m', required=True, multiple=True,107@click.option('--message', '-m', multiple=True,108 help='The commit message. If provided multiple times each '109 'argument gets converted into a new line.')110@click.argument('files', nargs=-1)111@pass_repo
5 unmodified lines
117118 If a list of files is omitted, all changes reported by "repo status"119 will be committed.120 """121 if not message:122 marker = '# Files to be committed:'123 hint = ['', '', marker, '#']124 for file in files:125 hint.append('# U %s' % file)126 message = click.edit('\n'.join(hint))127 if message is None:128 click.echo('Aborted!')129 return130 msg = message.split(marker)[0].rstrip()131 if not msg:132 click.echo('Aborted! Empty commit message')133 return134 else:135 msg = '\n'.join(message)136 click.echo('Files to be committed: %s' % (files,))122 click.echo('Commit message:\n' + '\n'.join(message))137 click.echo('Commit message:\n' + msg)138139140@cli.command(short_help='Copies files.')141@click.option('--force', is_flag=True,
10 unmodified lines
modified:tests/test_arguments.py+10 added-1 removed
125 unmodified lines
126127128def test_empty_nargs(runner):129 @click.command()130 @click.option('--arg', nargs=-1)130 @click.argument('arg', nargs=-1)131 def cmd(arg):132 click.echo('arg:' + '|'.join(arg))133134 result = runner.invoke(cmd, [])135 assert result.exit_code == 0136 assert result.output == 'arg:\n'137138 @click.command()139 @click.argument('arg', nargs=-1, required=True)140 def cmd2(arg):141 click.echo('arg:' + '|'.join(arg))142143 result = runner.invoke(cmd2, [])144 assert result.exit_code == 2145 assert 'Missing argument "arg"' in result.output146147148def test_eat_options(runner):149 @click.command()150 @click.option('-f')151 @click.argument('files', nargs=-1)
18 unmodified lines