Fixed a few broken command line switches

Change-Id: I54db710450972aab2d122e21cbea154366f07f9d
diff --git a/gerrit/README.md b/gerrit/README.md
new file mode 100644
index 0000000..f2cdf6c
--- /dev/null
+++ b/gerrit/README.md
@@ -0,0 +1,48 @@
+VOLTHA: Gerrit Queries
+======================
+
+A script for constructing gerrit JCL queries
+
+```bash
+% git clone ssh://gerrit.opencord.org/onf-scripts
+% cd onf-scripts/gerrit/bin
+
+% ./gerrit.sh –help
+```
+
+Gerrit by patch or user
+-----------------------
+
+| Jira | Command | Description |
+| ---- | ------- | ----------- |
+| [x](https://gerrit.opencord.org/dashboard/self) | gerrit.sh --dashboard | View user dashboard |
+| [x](https://gerrit.opencord.org/q/status:open)  | gerrit.sh --wip | Display unmerged patches |
+| [x](https://gerrit.opencord.org/q/status:open)  | gerrit.sh --all voltha-lib-go | Display metadata for a repo: branches, tags, source |
+| [x](https://gerrit.opencord.org/q/status:merged) | gerrit.sh --status merged [--user u] | View merged patches |
+
+My patches and pending reviews
+------------------------------
+
+| Jira | Command | Description |
+| ---- | ------- | ----------- |
+| [x](https://gerrit.opencord.org/q/owner:joey@opennetworking.org+status:open) | gerrit.sh --wip --me | Display my unmerged patches |
+
+Gerrit by repository
+--------------------
+
+| Jira | Command | Description |
+| ---- | ------- | ----------- |
+| [x](https://gerrit.opencord.org/q/voltha-lib-go+status:open) | gerrit.sh --patch voltha-lib-go | View open patches by repository | 
+
+Misc
+----
+
+| Jira | Command | Description |
+| ---- | ------- | ----------- |
+| [x](https://gerrit.opencord.org/plugins/gitiles/voltha-lib-go/+/refs/heads/master/VERSION) | gerrit.sh --view repo voltha-lib-go | View repository VERSION file |
+
+
+See Also
+--------
+
+- [Gerrit: Searching Changes](https://gerrit-review.googlesource.com/Documentation/user-search.html)
diff --git a/gerrit/bin/gerrit.sh b/gerrit/bin/gerrit.sh
index 4900ab1..3463960 100755
--- a/gerrit/bin/gerrit.sh
+++ b/gerrit/bin/gerrit.sh
@@ -27,10 +27,23 @@
 ##--------------------##
 ##---]  INCLUDES  [---##
 ##--------------------##
-source "${libdir}/filters/status.sh"
+source "${libdir}/filters/include.sh"
 source "${libdir}/usage/include.sh"
-# source "${libdir}/usage/main.sh"
 
+## --------------------------------------------------------------------
+## --------------------------------------------------------------------
+function error()
+{
+    cat <<ERROR
+
+** -----------------------------------------------------------------------
+**   IAM: ${FUNCNAME[1]}
+** ERROR: $@
+** -----------------------------------------------------------------------
+ERROR
+    echo 
+    exit 1
+}
 
 ## -----------------------------------------------------------------------
 ## -----------------------------------------------------------------------
@@ -86,7 +99,56 @@
     return
 }
 
+## -----------------------------------------------------------------------
+## Usage: $0 --status open --reviewer [u]
+## -----------------------------------------------------------------------
+function do_gerrit_review()
+{
+    local -n ref_urls=$1   ; shift
+    local -n ref_repos=$1   ; shift
+    local -n ref_status=$1 ; shift
 
+    ref_urls=()
+
+    # local stem='https://gerrit.opencord.org/q/project:voltha-go+status:open'
+    local stem='https://gerrit.opencord.org/q/'
+
+    local -a common=()
+    [[ -v me ]] && { common+=('reviewer:self') }
+
+    for reviewer in "${argv_reviewer[@]}"; do
+        common+=("reviewer:${reviewer}")
+    done
+
+    local repo
+    for repo in "${ref_repos[@]}";
+    do
+        local -a args=()
+        args+=("project:${repo}")
+        args+=("${common[@]}")
+
+        local url="$stem"
+        url+="$(join_by '+' "${args[@]}")"
+        ref_urls+=("$url")
+    done
+
+    ## If not repo specific then query all
+    if [[ ${#ref_urls[@]} -eq 0 ]]; then
+        local -a args=()
+        args=("${common[@]}")
+
+        local url="$stem"
+        url+="$(join_by '+' "${args[@]}")"
+        ref_urls+=("$url")
+    fi
+
+	# --debug)  declare -g -i debug=1 ;;
+    # --search) declare -g -i search=1 ;;
+    # --wip)    declare -g -i status_is_open=1 ;;
+
+    return
+}
+ 
 ## -----------------------------------------------------------------------
 ## Intent: Iterate over --admin values and generate repositories
 ## -----------------------------------------------------------------------
@@ -283,7 +345,7 @@
         --search) declare -g -i argv_search=1 ;;
 
         --me)
-            # declare -g -i argv_me=1
+            declare -g -i argv_me=1
             me+=("owner:${USER}@opennetworking.org")
             ;;
 
@@ -402,13 +464,20 @@
 
         --patch*)
             repo="$1"; shift
-            urls+=("https://gerrit.opencord.org/q/${repo}+stats:open")
+            urls+=("https://gerrit.opencord.org/q/${repo}+status:open")
             # https://gerrit.opencord.org/q/voltha-openolt-adapter-go
             ;;
-        --review)
-            urls+=('https://gerrit.opencord.org/c/aether-ci-management/+/34900')
+
+        --reviewer)
+            arg="$1"; shift
+            add_filter_reviewer "$arg"
+
+            declare -g -i argv_review=1
+            # Replace with: set -- '--review' "$@"
             ;;
 
+        --review) declare -g -i argv_review=1 ;;
+
         --ver*)
             [[ $# -eq 0 ]] && { error "Usage: $arg [str]"; }
             arg="$1"; shift
@@ -470,12 +539,18 @@
     esac
 done
 
-[[ -v argv_search ]] && { do_gerrit_search urls repos argv_status; }
-[[ -v admins ]] && { gen_admin_urls urls repos admins; }
+[[ -v argv_search ]]   && { do_gerrit_search urls repos argv_status; }
+[[ -v admins ]]      && { gen_admin_urls urls repos admins; }
+
+# -----------------------------------------------------------------------
+# Generalize:
+#   o --review function like a simple search filter.
+#   o piece missing is defining query URL stem= when needed.
+# -----------------------------------------------------------------------
+[[ -v argv_review ]] && { do_gerrit_review urls repos argv_status; }
 
 ## are --views working ?
 [[ "${#views[@]}" -gt 0 ]] && { gen_view_urls  urls repos views;  }
-# [[ ! -v views  ]] && { echo 'called'; gen_view_urls  urls repos views;  }
 
 if [[ ${#urls[@]} -eq 0 ]]; then
     declare -a show_all=() # show all for visiblity
diff --git a/gerrit/gerrit/filters/include.sh b/gerrit/gerrit/filters/include.sh
new file mode 100644
index 0000000..34c84ea
--- /dev/null
+++ b/gerrit/gerrit/filters/include.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# -----------------------------------------------------------------------
+# Copyright 2024 Open Networking Foundation Contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http:#www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# -----------------------------------------------------------------------
+# SPDX-FileCopyrightText: 2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+##--------------------##
+##---]  INCLUDES  [---##
+##--------------------##
+source "${libdir}/filters/status.sh"
+source "${libdir}/filters/reviewers.sh"
+
+: # ($?==0) for source script
+
+# [EOF]
diff --git a/gerrit/gerrit/filters/reviewers.sh b/gerrit/gerrit/filters/reviewers.sh
new file mode 100644
index 0000000..e9d65d2
--- /dev/null
+++ b/gerrit/gerrit/filters/reviewers.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+# -----------------------------------------------------------------------
+# Copyright 2024 Open Networking Foundation Contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http:#www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# -----------------------------------------------------------------------
+# SPDX-FileCopyrightText: 2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+## -----------------------------------------------------------------------
+## Intent: Update gerrit query to filter based on reviewer
+## -----------------------------------------------------------------------
+function add_filter_reviewer()
+{
+    local val="$1"; shift
+
+    [[ ! -v argv_reviewer ]] && { declare -g -a argv_reviewer=(); }
+    argv_reviewer+=("$val")
+
+    return
+} # add_reviewer_filter()
+
+## -----------------------------------------------------------------------
+## Intent: Merge reviewer attributes into a URL query
+## -----------------------------------------------------------------------
+function apply_filter_reviewer()
+{
+    local -n ref=$1; shift
+
+    [[ ! -v argv_reviewer ]] && { return; }
+
+    echo "REF=[${ref[@]}]"
+
+    local reviewer
+    for reviewer in "${argv_reviewer[@]}";
+    do
+        if [[ "${ref[-1]: -1:1}" != '/' ]]; then
+           ref[-1]+='+' # "+reviewer:${reviewer}"
+        fi
+
+        # https://gerrit.opencord.org/q/reviewer:open
+        # TODO: Do not apply + when
+        # ref[-1]+="+reviewer:${reviewer}"
+        ref[-1]+="reviewer:${reviewer}"
+    done
+
+    return
+}
+
+: # ($?==0) for source script
+
+# [EOF]
diff --git a/gerrit/gerrit/usage/main.sh b/gerrit/gerrit/usage/main.sh
index 94f822b..5fe3cd3 100644
--- a/gerrit/gerrit/usage/main.sh
+++ b/gerrit/gerrit/usage/main.sh
@@ -27,7 +27,6 @@
     cat <<EOH
 Usage: $0
   --all r          Load all metadata for a repository
-  --reviews        Load pending code review requests
 
   --access         Display gerrit ACLs
   --dash(boad)     Display my patch dashboard
@@ -65,6 +64,11 @@
     voltha-2.12      View a branch
     v2.3.3           View a tag
 
+[REVIEW]
+  --review         Load pending code review requests
+  --review --me    Load only my pending requests
+  --reviewer       Load reviews by user
+
 [FILTER(s)]
   --status [s]       Filter query results by status={open,merged,closed}
     s=open (is:open)
diff --git a/jira/bin/jira-search.sh b/jira/bin/jira-search.sh
index 829cb4a..51959f6 100755
--- a/jira/bin/jira-search.sh
+++ b/jira/bin/jira-search.sh
@@ -72,7 +72,14 @@
 ## --------------------------------------------------------------------
 function error()
 {
-    echo "ERROR ${FUNCNAME[1]}: $@"
+    cat <<ERROR
+
+** -----------------------------------------------------------------------
+**   IAM: ${FUNCNAME[1]}
+** ERROR: $@
+** -----------------------------------------------------------------------
+ERROR
+    echo 
     exit 1
 }
 
diff --git a/jira/review.log b/jira/review.log
new file mode 100644
index 0000000..2c04269
--- /dev/null
+++ b/jira/review.log
@@ -0,0 +1,12 @@
+remote: 
+remote: Processing changes: (\)        
+remote: Processing changes: refs: 1, new: 1 (\)        
+remote: Processing changes: refs: 1, new: 1 (\)        
+remote: Processing changes: refs: 1, new: 1, done            
+remote: 
+remote: SUCCESS        
+remote: 
+remote:   https://gerrit.opencord.org/c/onf-scripts/+/35169 Update help text [NEW]        
+remote: 
+To ssh://gerrit.opencord.org/onf-scripts
+ * [new reference]   HEAD -> refs/for/master%topic=dev-joey