Skip to content

Commit e308d82

Browse files
committed
Fixed duplicate arguments in group bug
1 parent b76d647 commit e308d82

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

koi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,13 @@ function __addgroup {
446446
__argsingroup=( "${__argsingroup[@]}" "$__arg" )
447447
done
448448

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+
449456
# verify arguments in mutually exclusive group are not dependent on each other
450457
local __argingroup __dep __founddependent __founddependency
451458
if [[ "$__property" == "XOR" ]] ; then

tests/test_groups/test_groups_invalid.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ function test_groups_invalid_shortoptions_only {
114114
echo "$flag $glad $pos"
115115
}
116116

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+
117125
# ========= ASSERTIONS ========= #
118126
function koitest_run {
119127
runtest test_groups_invalid_too_few_arguments __error__ "--flag"
@@ -128,4 +136,5 @@ function koitest_run {
128136
runtest test_groups_invalid_action_positionalarray __error__ "-f" "arg" "arg"
129137
runtest test_groups_invalid_argument_required __error__ "--glad"
130138
runtest test_groups_invalid_shortoptions_only __error__ "-f" "-g"
139+
runtest test_groups_invalid_duplicate_arguments __error__ "-aaa"
131140
}

0 commit comments

Comments
 (0)