Cleanup conditional construction logic for --resolved and --user
Signed-off-by: Joey Armstrong <jarmstrong@linuxfoundation.org>
Change-Id: I2080713f8c340aa234923e0a226030ec1b666133
diff --git a/jira/jira-search/resolved.sh b/jira/jira-search/resolved.sh
index 88b6835..cf6bf31 100644
--- a/jira/jira-search/resolved.sh
+++ b/jira/jira-search/resolved.sh
@@ -10,13 +10,26 @@
function get_jcl_resolved()
{
local -n ref=$1; shift
+ local -i count=${#ref[@]}
local -a tmp=()
do_resolved tmp
- ref+=("$tmp")
-
- local query="$(join_by 'OR' "${tmp[0]}")"
- ref+=("($query)")
+
+ ## --------------------------
+ ## Construct resolved queries
+ ## --------------------------
+ local query="$(join_by ' OR ' "${tmp[@]}")"
+
+ ## ----------------------------------------
+ ## Normalize parens for the composite query
+ ## ----------------------------------------
+ if [[ ${#ref[@]} -eq 0 ]]; then
+ ref+=("$query")
+ else
+ local buffer
+ buffer="$(join_by ' AND ' "(${ref[@]})" "($query)")"
+ ref=("$buffer")
+ fi
return
}
@@ -44,12 +57,23 @@
{
declare -n ans=$1; shift
- [[ -v resolved_start ]] && { ans+=("(Resolved >= $resolved_start)"); }
- [[ -v resolved_end ]] && { ans+=("(Resolved <= $resolved_end)"); }
+ # --resolved-in {start} {end} can resolve join({and,or}) ambiguity
+ # [[ -v resolved_start ]] && { ans+=("(Resolved >= $resolved_start)"); }
+ # [[ -v resolved_end ]] && { ans+=("(Resolved <= $resolved_end)"); }
+ declare -a joinby=()
+ [[ -v resolved_start ]] && { joinby+=("(Resolved >= $resolved_start)"); }
+ [[ -v resolved_end ]] && { joinby+=("(Resolved <= $resolved_end)"); }
+
+ if [[ ${#joinby[@]} -lt 2 ]]; then
+ ans+=("${joinby[@]}")
+ else
+ filter="$(join_by ' AND ' "${joinby[@]}")"
+ ans+=("(${filter})")
+ fi
+
if [[ -v resolved_excl ]]; then
filter="$(join_by ',' "${resolved_excl[@]}")"
- declare -p filter
ans+=( "(resolution NOT IN ($filter))" )
fi
@@ -58,14 +82,12 @@
ans+=( "(resolution IN ($filter))" )
fi
- [[ -v resolved_not_empty ]] \
- && { ans+=('(resolved IS NOT EMPTY)'); } \
- || { true; }
-
- [[ -v resolved_is_empty ]] \
- && { ans+=('(resolved IS EMPTY)'); } \
- || { true; }
-
+ if [[ -v resolved_not_empty ]]; then
+ ans+=('(resolved IS NOT EMPTY)')
+ elif [[ -v resolved_is_empty ]]; then
+ ans+=('(resolved IS EMPTY)')
+ fi
+
return
}