From 6f60b639f5e7d244709ccd2eee45ce3964d2c96e Mon Sep 17 00:00:00 2001
From: Kostis Anagnostopoulos <ankostis@gmail.com>
Date: Tue, 17 May 2022 20:29:50 +0300
Subject: [PATCH] feat(setup) exec many actions in cmdline; >

* feat: provide help-msg if --help/-h given anywhere in args.
* refact: simplify help-msg formatting in one cmd.
---
 setup-account.sh | 41 ++++++++++++++++++++++++++---------------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/setup-account.sh b/setup-account.sh
index 47a1142..80f361b 100755
--- a/setup-account.sh
+++ b/setup-account.sh
@@ -279,20 +279,31 @@ function all {
     done
 }
 
-if [[ $# -eq 1 && ( "$1" = "-h" || "$1" = "--help" ) ]]; then
-    echo -e "$mycmd - actions to setup a BDAP user account.\n"
-    echo -e "SYNTAX:\n    $mycmd\n    $mycmd ACTION\nWHERE:\n    ACTION is one of:"
-    _list_all_actions
-    echo -e '\nWithout any args, it  launches `all` actions, in order.'
-    echo -e '\nNOTES:\n    * The `upd30_git_user` action awaits interactively input from the user.'
-    echo -e '    * You may have to logout & re-login after `upd40_bashrc_conda_init`,
-      for `upd50_create_conda_env` to succeed.'
-    echo -e '    * You can repeatedly run this script, until all action succeed.'
-elif [[ $# -eq 0 ]]; then
-    echo "Running all actions..."
-    all
+## Trick to search if NOT help- asked
+# from: https://superuser.com/a/1002826/227922
+if [[ "${@#-h}" = "$@" && "${@#--help}" = "$@" ]]; then
+    if [[ $# -eq 0 ]]; then
+        echo "Running all actions..."
+        all
+    else
+        echo "Running x$# actions: '${@}'"
+        ## execute the asked action.
+        for cmd in "${@}"; do
+            $cmd
+        done
+    fi
 else
-    ## execute the asked action.
-    echo "Running '${@}' action..."
-    "${@}"
+    echo "$mycmd - actions to setup a BDAP user account.
+SYNTAX:
+    $mycmd [ACTION]...
+WHERE:
+    ACTION is one of:
+$(_list_all_actions)
+NOTES:
+    * Without any args, it  launches 'all' actions above, in that order.
+    * The 'upd30_git_user_XXX' actions awaits interactively input from the user.
+    * You may have to logout & re-login after 'upd40_bashrc_conda_init',
+      for 'upd50_create_conda_env' to succeed.
+    * You can repeatedly run this script, until all actions succeed.
+"
 fi
-- 
GitLab