File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -446,6 +446,13 @@ function __addgroup {
446
446
__argsingroup=( " ${__argsingroup[@]} " " $__arg " )
447
447
done
448
448
449
+ local __argingroupduplicates
450
+ __argingroupduplicates=$( printf ' %s\n' " ${__argsingroup[@]} " | awk ' !($0 in seen){seen[$0];c++} END {print c}' )
451
+ if [[ " $__argingroupduplicates " != " ${# __argsingroup[@]} " ]] ; then
452
+ __errortext -c " $koiname : __addgroup err: arguments in group must be unique"
453
+ return 1
454
+ fi
455
+
449
456
# verify arguments in mutually exclusive group are not dependent on each other
450
457
local __argingroup __dep __founddependent __founddependency
451
458
if [[ " $__property " == " XOR" ]] ; then
Original file line number Diff line number Diff line change @@ -114,6 +114,14 @@ function test_groups_invalid_shortoptions_only {
114
114
echo " $flag $glad $pos "
115
115
}
116
116
117
+ function test_groups_invalid_duplicate_arguments {
118
+ __addarg " -a" " --aaa" " flag" " optional" " " " help text"
119
+ __addgroup " wrong" " XOR" " optional" " --aaa" " --aaa"
120
+ __parseargs " $@ "
121
+
122
+ echo " $aaa "
123
+ }
124
+
117
125
# ========= ASSERTIONS ========= #
118
126
function koitest_run {
119
127
runtest test_groups_invalid_too_few_arguments __error__ " --flag"
@@ -128,4 +136,5 @@ function koitest_run {
128
136
runtest test_groups_invalid_action_positionalarray __error__ " -f" " arg" " arg"
129
137
runtest test_groups_invalid_argument_required __error__ " --glad"
130
138
runtest test_groups_invalid_shortoptions_only __error__ " -f" " -g"
139
+ runtest test_groups_invalid_duplicate_arguments __error__ " -aaa"
131
140
}
You can’t perform that action at this time.
0 commit comments