update_program_fw: Normalise arg list processing

Normalise the list processing to handle comma and space
separated arguments.

BUG=none
TEST=Run dry-run

Change-Id: I2b5ca8ac3fcedc54934eab8e7e8a9f0c155e2f26
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2310021
Tested-by: Andrew McRae <amcrae@chromium.org>
Reviewed-by: Kangheui Won <khwon@chromium.org>
Commit-Queue: Kangheui Won <khwon@chromium.org>
diff --git a/contrib/update_program_fw b/contrib/update_program_fw
index 207af55..b61b6c9 100755
--- a/contrib/update_program_fw
+++ b/contrib/update_program_fw
@@ -9,7 +9,7 @@
 # for review.
 #
 # Usage:
-#   ./update_program_fw --board=program --release=NNNNN.nn [ --reviewer=reviewer ]
+#   ./update_program_fw --board=program --release=NNNNN.nn [ --reviewer=reviewers ]
 #                       [ --project=proj... ]
 # E.g:
 #   ./update_program_fw --board=puff --release=13291 --reviewer=amcrae@google.com
@@ -41,7 +41,7 @@
 DEFINE_string skip "${DEFAULT_SKIP}" "Skip these projects (comma separated list)" s
 DEFINE_boolean build "${FLAGS_TRUE}" "Attempt to build coreboot"
 DEFINE_boolean program "${FLAGS_TRUE}" "Update the version in the base program.star"
-DEFINE_string reviewer "${DEFAULT_REVIEWER}" "The reviewer to send the CLs to (optional)"
+DEFINE_string reviewer "${DEFAULT_REVIEWER}" "The reviewer(s) to send the CLs to (optional)"
 DEFINE_string test "none" "The 'TEST=' string added to the commit message"
 DEFINE_boolean dryrun "${FLAGS_FALSE}" "Do not perform any actions, just validate and print arguments"
 DEFINE_boolean verify "${FLAGS_TRUE}" "Ask for verification before proceeding"
@@ -116,6 +116,7 @@
 }
 #
 # return 'yes' or 'no' for boolean true or false
+#
 yes_no() {
   if [[ "${1}" -eq  "${FLAGS_FALSE}" ]]; then
     echo -n "no"
@@ -124,6 +125,18 @@
   fi
 }
 #
+# Normalise a comma or space separated argument or arguments to
+# a single set of space separated arguments.
+#
+rd_list() {
+  local l=()
+  for arg in "$@"; do
+    IFS=', ' read -r -a la <<< "${arg}"
+    l+=("${la[@]}")
+  done
+  echo "${l[@]}"
+}
+#
 # Return true if repo has changes.
 #
 changed() {
@@ -225,14 +238,18 @@
   cd "${BDIR}"
   mapfile -t PROJLIST < <(ls)
 else
-  IFS=',' read -r -a PROJLIST <<< "${FLAGS_project}"
+  read -r -a PROJLIST <<< "$(rd_list "${FLAGS_project}")"
 fi
 #
+# Get list of reviewers (if any)
+#
+read -r -a REVIEWERS <<< "$(rd_list "${FLAGS_reviewer}")"
+#
 # Filter out the projects that are to be skipped.
 #
 if [[ -n "${FLAGS_skip}" ]]; then
   PROJECTS=()
-  IFS=',' read -r -a SKIP_ARRAY <<< "${FLAGS_skip}"
+  read -r -a SKIP_ARRAY <<< "$(rd_list "${FLAGS_skip}")"
   # Validate skipped projects
   for S in "${SKIP_ARRAY[@]}"; do
     check_project "${S}"
@@ -247,7 +264,7 @@
   PROJECTS=("${PROJLIST[@]}")
 fi
 #
-# Valid bug number (if any).
+# Validate bug number (if any).
 # Must be of the form b:nnnnn or chromium:nnnnn
 #
 if [[ "${FLAGS_bug}" != "none" ]]; then
@@ -298,12 +315,12 @@
 echo "Minor version of release:      ${MINOR_VERSION}"
 echo "BUG string used in commit:     ${FLAGS_bug}"
 echo "TEST string used in commit:    ${FLAGS_test}"
-echo "Reviewer assigned to CLs:      ${FLAGS_reviewer:-None}"
+echo "Reviewer(s) assigned to CLs:   ${REVIEWERS[*]}"
 echo "repo branch to be used is:     ${BRANCH}"
-echo "Update program.star version:   $(yes_no ${FLAGS_program})"
-echo "Coreboot build enabled:        $(yes_no ${FLAGS_build})"
-echo "Dry run requested:             $(yes_no ${FLAGS_dryrun})"
-echo "Verify before proceeding:      $(yes_no ${FLAGS_verify})"
+echo "Update program.star version:   $(yes_no "${FLAGS_program}")"
+echo "Coreboot build enabled:        $(yes_no "${FLAGS_build}")"
+echo "Dry run requested:             $(yes_no "${FLAGS_dryrun}")"
+echo "Verify before proceeding:      $(yes_no "${FLAGS_verify}")"
 #
 if [[ "${FLAGS_dryrun}" -eq  "${FLAGS_TRUE}" ]]; then
   echo "Dry run requested, exiting"
@@ -347,7 +364,7 @@
 ${FLAGS_board}: Update program firmware to ${FLAGS_release}
 
 Autogenerated by:
-${COMMAND} ${CMDARGS}
+$(echo "${COMMAND} ${CMDARGS}" | fold -s -w 70 | sed '2,$s/^/    /')
 
 BUG=${FLAGS_bug}
 TEST=${FLAGS_test}
@@ -533,9 +550,9 @@
 # If reviewer is set, then add them to the CLs
 #
 if [[ -n "${FLAGS_reviewer}" ]]; then
-  echo "Sending CLs ${ALL_CLS} to ${FLAGS_reviewer} for review"
+  echo "Sending CLs ${ALL_CLS} to ${REVIEWERS[*]} for review"
   for cl in ${ALL_CLS}; do
-    gerrit -i reviewers "${cl}" "${FLAGS_reviewer}"
+    gerrit -i reviewers "${cl}" "${REVIEWERS[@]}"
   done
 else
   echo "Send CLs for review by running:"