Modify switch handling to centralize parse and validation for --{foo}-is-empty
Signed-off-by: Joey Armstrong <jarmstrong@linuxfoundation.org>
Change-Id: Ia8b955f5451b5b7938d48abdea681e5c8396b376
diff --git a/jira/jira-search/is_empty.sh b/jira/jira-search/is_empty.sh
new file mode 100644
index 0000000..fe6e9d1
--- /dev/null
+++ b/jira/jira-search/is_empty.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+
+## -----------------------------------------------------------------------
+## Intent: Detect if the --{labels,required}-is-empty switch is valid
+## -----------------------------------------------------------------------
+function is_switch_valid__is_empty()
+{
+ local raw="$1"; shift # --{foo}-is-empty
+
+ declare -a valid=()
+ valid+=('label')
+ valid+=('resolved')
+
+ # --required-is-empty => required
+ local val="$raw"
+ val="${val:2}" # remove prefix --
+ val="${val%-is-empty}" # remove suffix token-name
+
+ if [[ " ${valid[@]} " =~ " ${val} " ]]; then
+ is_empty+=("$val")
+ else
+ error "Detected invalid --is-empty switch [$arg]"
+ fi
+
+ return
+}
+
+: # ($?=0) for source $include
+
+# [EOF]