Skip to content
Myr

Fixed argument handling for "-" and added test. This fixes #77

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 ed9594d · Browse files · 2 files+26 added−2 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+26 added−2 removed

  • tests:+23 added−0 removed
  • other:+3 added−2 removed

2 files+26 added−2 removed

modified:click/parser.py+3 added-2 removed
178 unmodified lines
179180 def _process_args_for_options(self, state):181 while state.rargs:182 arg = state.rargs[0]183 arglen = len(arg)184 # Double dash es always handled explicitly regardless of what185 # prefixes are valid.186 if arg == '--':187 del state.rargs[0]188 return188 elif arg[0:2] in self._opt_prefixes:189 elif arg[:2] in self._opt_prefixes and arglen > 2:190 # process a single long option (possibly with value(s))191 self._process_long_opt(state)191 elif arg[:1] in self._opt_prefixes and len(arg) > 1:192 elif arg[:1] in self._opt_prefixes and arglen > 1:193 # process a cluster of short options (possibly with194 # value(s) for the last one only)195 self._process_short_opts(state)196 elif self.allow_interspersed_args:
125 unmodified lines
modified:tests/test_arguments.py+23 added
45 unmodified lines
4647 result = runner.invoke(copy, ['foo', 'bar'])48 assert result.exit_code == 249 assert 'Got unexpected extra argument (bar)' in result.output505152def test_file_args(runner):53 @click.command()54 @click.argument('input', type=click.File('rb'))55 @click.argument('output', type=click.File('wb'))56 def inout(input, output):57 while True:58 chunk = input.read(1024)59 if not chunk:60 break61 output.write(chunk)6263 with runner.isolated_filesystem():64 result = runner.invoke(inout, ['-', 'hello.txt'], input='Hey!')65 assert result.output == ''66 assert result.exit_code == 067 with open('hello.txt', 'rb') as f:68 assert f.read() == b'Hey!'6970 result = runner.invoke(inout, ['hello.txt', '-'])71 assert result.output == 'Hey!'72 assert result.exit_code == 0