Repair broken JCL construction for a few switches
jira-search.sh
--------------
o Declare more array vars for gathering input.
o Replace declare with local within functions.
o Refactored arg detection to set parsting state variables.
o Replace inline AND/OR construction with list join on and/or.
Too many edge cases can leave a AND/OR token prefix or suffix
breaking the JCL query line.
o do_labels logic updated to handle --label-is-empty and construct
--excl and --incl arguments as standalone paren wrapped terms.
jira-search/getopt/detect-modifiers.sh
--------------------------------------
o when -and, -or, -in, -excl, -incl, -is-empty switch modifiers are
detected set global switch parsing state variables.
Signed-off-by: Joey Armstrong <jarmstrong@linuxfoundation.org>
Change-Id: Ib67bbf1a6389c8d9e9a3ac70911429118228c683
diff --git a/jira/jira-search/getopt/detect-modifiers.sh b/jira/jira-search/getopt/detect-modifiers.sh
new file mode 100644
index 0000000..84a1afd
--- /dev/null
+++ b/jira/jira-search/getopt/detect-modifiers.sh
@@ -0,0 +1,95 @@
+#!/bin/bash
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+
+## -----------------------------------------------------------------------
+## Intent: Set state flags for parsing based on detection of switch modifiers
+## -----------------------------------------------------------------------
+function getopt_detect_modifiers()
+{
+ local arg="$1"; shift
+
+ local -a patterns=()
+ patterns+=('and' 'or')
+ patterns+=('excl' 'incl')
+ patterns+=('in' 'not')
+ patterns+=('is-empty')
+
+ unset getopt_argv_AND
+ unset getopt_argv_EXCL
+ unset getopt_argv_INCL
+ unset getopt_argv_IN
+ unset getopt_argv_IS_EMPTY
+ unset getopt_argv_NOT
+ unset getopt_argv_OR
+
+ local pattern
+ for pattern in "${patterns[@]}";
+ do
+ # echo "** ${FUNCNAME} pattern=[$pattern], arg=[$arg]"
+ case "$pattern" in
+ 'and')
+ case "$arg" in
+ *'-'[aA][nN][dD]*) declare -g -i getopt_argv_AND=1 ;;
+ esac
+ ;;
+
+ 'or')
+ case "$arg" in
+ *'-'[oO][rR]*)
+ declare -g -i getopt_argv_OR=1
+ ;;
+ esac
+ ;;
+
+ 'excl')
+ case "$arg" in
+ *'-'[eE][xX][cC][lL]*) declare -g -i getopt_argv_EXCL=1 ;;
+ esac
+ ;;
+
+ 'incl')
+ case "$arg" in
+ *'-'[iI][nN][cC][lL]*) declare -g -i getopt_argv_INCL=1 ;;
+ esac
+ ;;
+
+ 'in')
+ if [[ ! -v getopt_argv_INCL ]]; then
+ case "$arg" in
+ *'-'[iI][nN]*) declare -g -i getopt_argv_IN=1 ;;
+ esac
+ fi
+ ;;
+
+ 'is-empty')
+ case "$arg" in
+ *'-'[iI][sS]-[eE][mM][pP][tT][yY]) declare -g -i getopt_argv_IS_EMPTY=1 ;;
+ esac
+ ;;
+
+ 'not')
+ case "$arg" in
+ *'-'[nN][oO][tT]*) declare -g -i getopt_argv_NOT=1 ;;
+ esac
+ ;;
+
+ esac
+
+ done
+
+ if false; then
+ [[ -v getopt_argv_AND ]] && { declare -p getopt_argv_AND; }
+ [[ -v getopt_argv_EXCL ]] && { declare -p getopt_argv_EXCL; }
+ [[ -v getopt_argv_INCL ]] && { declare -p getopt_argv_INCL; }
+ [[ -v getopt_argv_IN ]] && { declare -p getopt_argv_IN; }
+ [[ -v getopt_argv_IS_EMPTY ]] && { declare -p getopt_argv_IS_EMPTY; }
+ [[ -v getopt_argv_NOT ]] && { declare -p getopt_argv_NOT; }
+ [[ -v getopt_argv_OR ]] && { declare -p getopt_argv_OR; }
+ fi
+
+ : # return $?==0
+ return
+}
+
+# [EOF]