Skip to content

Commit

Permalink
Merge pull request #61 from wcarhart/bugfix/group-duplicates
Browse files Browse the repository at this point in the history
Fixed duplicate arguments in group bug
  • Loading branch information
wcarhart authored May 13, 2020
2 parents b76d647 + e308d82 commit 8d030a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions koi
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,13 @@ function __addgroup {
__argsingroup=( "${__argsingroup[@]}" "$__arg" )
done

local __argingroupduplicates
__argingroupduplicates=$(printf '%s\n' "${__argsingroup[@]}" | awk '!($0 in seen){seen[$0];c++} END {print c}')
if [[ "$__argingroupduplicates" != "${#__argsingroup[@]}" ]] ; then
__errortext -c "$koiname: __addgroup err: arguments in group must be unique"
return 1
fi

# verify arguments in mutually exclusive group are not dependent on each other
local __argingroup __dep __founddependent __founddependency
if [[ "$__property" == "XOR" ]] ; then
Expand Down
9 changes: 9 additions & 0 deletions tests/test_groups/test_groups_invalid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ function test_groups_invalid_shortoptions_only {
echo "$flag $glad $pos"
}

function test_groups_invalid_duplicate_arguments {
__addarg "-a" "--aaa" "flag" "optional" "" "help text"
__addgroup "wrong" "XOR" "optional" "--aaa" "--aaa"
__parseargs "$@"

echo "$aaa"
}

# ========= ASSERTIONS ========= #
function koitest_run {
runtest test_groups_invalid_too_few_arguments __error__ "--flag"
Expand All @@ -128,4 +136,5 @@ function koitest_run {
runtest test_groups_invalid_action_positionalarray __error__ "-f" "arg" "arg"
runtest test_groups_invalid_argument_required __error__ "--glad"
runtest test_groups_invalid_shortoptions_only __error__ "-f" "-g"
runtest test_groups_invalid_duplicate_arguments __error__ "-aaa"
}

0 comments on commit 8d030a8

Please sign in to comment.