From e308d82d428db3d04b1cc468eeaeedf9e708d432 Mon Sep 17 00:00:00 2001 From: Will Carhart Date: Tue, 12 May 2020 20:55:38 -0700 Subject: [PATCH] Fixed duplicate arguments in group bug --- koi | 7 +++++++ tests/test_groups/test_groups_invalid.sh | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/koi b/koi index eee2692..377fcd2 100755 --- a/koi +++ b/koi @@ -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 diff --git a/tests/test_groups/test_groups_invalid.sh b/tests/test_groups/test_groups_invalid.sh index b72890a..4eed19e 100755 --- a/tests/test_groups/test_groups_invalid.sh +++ b/tests/test_groups/test_groups_invalid.sh @@ -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" @@ -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" } \ No newline at end of file