Commit 9d1b71736ad13e498537d1c7b3b45d94f078c696
1 parent
723b284b47
Detect repeated arguments and report them.
Showing 2 changed files with 20 additions and 0 deletions Side-by-side Diff
antigen.zsh
... | ... | @@ -391,6 +391,11 @@ antigen () { |
391 | 391 | local name="${${name_spec%\?}%:}" |
392 | 392 | local value="$1" |
393 | 393 | |
394 | + if echo "$code" | grep -qm1 "^local $name="; then | |
395 | + echo "Argument '$name' repeated with the value '$value'". >&2 | |
396 | + return | |
397 | + fi | |
398 | + | |
394 | 399 | --add-var $name "$value" |
395 | 400 | |
396 | 401 | shift |
... | ... | @@ -418,6 +423,11 @@ antigen () { |
418 | 423 | local value="${arg#*=}" |
419 | 424 | fi |
420 | 425 | |
426 | + if echo "$code" | grep -qm1 "^local $name="; then | |
427 | + echo "Argument '$name' repeated with the value '$value'". >&2 | |
428 | + return | |
429 | + fi | |
430 | + | |
421 | 431 | # The specification for this argument, used for validations. |
422 | 432 | local arg_line="$(echo "$keyword_args" | grep -m1 "^$name:\??\?")" |
423 | 433 |
tests/arg-parser.t
... | ... | @@ -52,3 +52,13 @@ Positional argument as a keyword argument. |
52 | 52 | |
53 | 53 | $ parse --url=some-url |
54 | 54 | local url='some-url' |
55 | + | |
56 | +Repeated keyword arguments. | |
57 | + | |
58 | + $ parse --url=url1 --url=url2 | |
59 | + Argument 'url' repeated with the value 'url2'. | |
60 | + | |
61 | +Repeated, once as positional and once more as keyword. | |
62 | + | |
63 | + $ parse url1 --url=url2 | |
64 | + Argument 'url' repeated with the value 'url2'. |