From 9d1b71736ad13e498537d1c7b3b45d94f078c696 Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Date: Sat, 11 Aug 2012 15:24:21 +0530 Subject: [PATCH] Detect repeated arguments and report them. --- antigen.zsh | 10 ++++++++++ tests/arg-parser.t | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/antigen.zsh b/antigen.zsh index 214ce95..af8c80e 100644 --- a/antigen.zsh +++ b/antigen.zsh @@ -391,6 +391,11 @@ antigen () { local name="${${name_spec%\?}%:}" local value="$1" + if echo "$code" | grep -qm1 "^local $name="; then + echo "Argument '$name' repeated with the value '$value'". >&2 + return + fi + --add-var $name "$value" shift @@ -418,6 +423,11 @@ antigen () { local value="${arg#*=}" fi + if echo "$code" | grep -qm1 "^local $name="; then + echo "Argument '$name' repeated with the value '$value'". >&2 + return + fi + # The specification for this argument, used for validations. local arg_line="$(echo "$keyword_args" | grep -m1 "^$name:\??\?")" diff --git a/tests/arg-parser.t b/tests/arg-parser.t index 2b225ab..b1f58e5 100644 --- a/tests/arg-parser.t +++ b/tests/arg-parser.t @@ -52,3 +52,13 @@ Positional argument as a keyword argument. $ parse --url=some-url local url='some-url' + +Repeated keyword arguments. + + $ parse --url=url1 --url=url2 + Argument 'url' repeated with the value 'url2'. + +Repeated, once as positional and once more as keyword. + + $ parse url1 --url=url2 + Argument 'url' repeated with the value 'url2'. -- 2.0.0