From 9e14f3873523c09e89f184074d92415ba84eb077 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Fri, 14 Jan 2022 15:39:14 +1100 Subject: [PATCH] Fix issue where a filter matches one item exactly and others partially. --- gnscli.sh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/gnscli.sh b/gnscli.sh index 852e620..6193852 100755 --- a/gnscli.sh +++ b/gnscli.sh @@ -2349,6 +2349,7 @@ function validate_action_obs() { # infoname whattolist actionfilter showerroropt local infoname whattolist actionfilter showerroropt local selobname="" selobuuid="" local retvar_obname retvar_obuuid multiallowed + local gotexactmatch=0 infoname="$1" whattolist="$2" actionfilter="$3" @@ -2394,11 +2395,35 @@ debug "alluuids is $alluuids" o_arr=($allobs) ou_arr=($alluuids) + if [[ $nobs -gt 1 && $multiallowed -eq 0 ]]; then debug "actionfilter=$actionfilter" + if [[ -n $actionfilter ]]; then + local x + # do any of them match exactly? + for x in ${!o_arr[@]}; do + if [[ "-f${o_arr[$x]}" == $actionfilter ]]; then + selobname="${o_arr[$x]}" + selobuuid="${ou_arr[$x]}" + unset o_arr + unset ou_arr + o_arr=($selobname) + ou_arr=($selobuuid) + allobs="$selobname" + alluuids="$selobuuid" + nobs=1 + nuuids=1 - inform "'${INFORMCOLB}${actionfilter}${INFORMCOL}' matched multiple ${whattolist}s" - narrowdown "$whattolist" "$allobs" "$alluuids" selobname selobuuid || rv=1 + gotexactmatch=1 + fi + done + fi + + if [[ $gotexactmatch -ne 1 ]]; then + + inform "'${INFORMCOLB}${actionfilter:2}${INFORMCOL}' matched multiple ${whattolist}s" + narrowdown "$whattolist" "$allobs" "$alluuids" selobname selobuuid || rv=1 + fi else selobname="$allobs" selobuuid="$alluuids"