feat(user/bkots):Add script to run ots recursively
[BK-2020-03.git] / unitproc / bktemp-processArgs
index ca29c35235b9f9fded5650bc8ac9b7b0b779f397..27679a2550db6177140cccf0e033cd39ed297dc8 100644 (file)
@@ -4,6 +4,7 @@
 #==BEGIN Define script parameters==
 #===BEGIN Define variables===
 :
+declare -ag arrayPosArgs
 #===END Define variables===
 
 #===BEGIN Declare local script functions===
@@ -17,7 +18,7 @@ vbm() {
     # Input: arg1: string
     #        vars: opVerbose
     # Output: stderr
-    # Depends: bash 5.0.3, GNU-coreutils 8.30 (echo, date)
+    # Depends: bash 5.1.16, GNU-coreutils 8.30 (echo, date)
 
     if [ "$opVerbose" = "true" ]; then
        functionTime="$(date --iso-8601=ns)"; # Save current time in nano seconds.
@@ -30,7 +31,7 @@ vbm() {
 showUsage() {
     # Desc: Display script usage information
     # Usage: showUsage
-    # Version 0.0.1
+    # Version 0.0.2
     # Input: none
     # Output: stdout
     # Depends: GNU-coreutils 8.30 (cat)
@@ -50,18 +51,21 @@ showUsage() {
         -I, --input-dir
                 Define input directory path.
         -o, --output-file
-                Define output file path
+                Define output file path.
         -O, --output-dir
-                Define output directory path
+                Define output directory path.
+        --
+                Indicate end of options.
 
     EXAMPLE:
       bktemp-processArgs -o foo.txt
+      bktemp-processArgs -o foo.txt -- some_file.txt
 EOF
 } # Display information on how to use this script.
 showVersion() {
     # Desc: Displays script version and license information.
     # Usage: showVersion
-    # Version: 0.0.1
+    # Version: 0.0.2
     # Input: scriptVersion   var containing version string
     # Output: stdout
     # Depends: vbm(), yell, GNU-coreutils 8.30
@@ -70,14 +74,14 @@ showVersion() {
     vbm "DEBUG:showVersion function called."
 
     cat <<'EOF'
-bktemp-processArgs 0.0.1
+bktemp-processArgs 1.0.0
 Copyright (C) 2021 Steven Baltakatei Sandoval
 License GPLv3: GNU GPL version 3
 This is free software; you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.
 
-    GNU Coreutils 8.30
-    Copyright (C) 2018 Free Software Foundation, Inc.
+    GNU Coreutils 8.32
+    Copyright (C) 2020 Free Software Foundation, Inc.
     License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
     This is free software: you are free to change and redistribute it.
     There is NO WARRANTY, to the extent permitted by law.
@@ -90,7 +94,7 @@ EOF
 processArgs() {
     # Desc: Processes arguments provided to script.
     # Usage: processArgs "$@"
-    # Version: 0.0.1
+    # Version: 1.0.0
     # Input: "$@"          (list of arguments provided to the function)
     # Output: Sets following variables used by other functions:
     #   opVerbose            Indicates verbose mode enable status.  (ex: "true", "false")
@@ -98,15 +102,18 @@ processArgs() {
     #   pathFileOut1         Path to output file.
     #   pathDirIn1           Path to input directory.
     #   pathFileIn1          Path to input file.
-    #   opFileOut1_overwrite Indicates whether file pathFileOut1 should be overwritten (ex: "true", "false')
+    #   opFileOut1_overwrite Indicates whether file pathFileOut1 should be overwritten (ex: "true", "false").
+    #   arrayPosArgs         Array of remaining positional argments
     # Depends:
     #   yell()           Displays messages to stderr.
     #   vbm()            Displays messsages to stderr if opVerbose set to "true".
-    #   showUsage()      Displays usage information about parent script
-    #   showVersion()    Displays version about parent script
-    # External dependencies: bash (5.0.3), echo
+    #   showUsage()      Displays usage information about parent script.
+    #   showVersion()    Displays version about parent script.
+    #   arrayPosArgs     Global array for storing non-option positional arguments (i.e. arguments following the `--` option).
+    # External dependencies: bash (5.1.16), echo
     # Ref./Attrib.:
     #  [1]: Marco Aurelio (2014-05-08). "echo that outputs to stderr". https://stackoverflow.com/a/23550347
+    #  [2]: "Handling positional parameters" (2018-05-12). https://wiki.bash-hackers.org/scripting/posparams
 
     # Initialize function
     vbm "DEBUG:processArgs function called."
@@ -169,8 +176,16 @@ processArgs() {
                    yell "ERROR:Specified output directory is not valid:""$2";
                    yell "Exiting.";
                    exit 1;
-               fi ;; 
-           *) yell "ERROR: Unrecognized argument."; exit 1;; # Handle unrecognized options. See [1].
+               fi ;;
+            --) # End of all options. See [2].
+                shift;
+                for arg in "$@"; do
+                    vbm "DEBUG:adding to arrayPosArgs:$arg";
+                    arrayPosArgs+=("$arg");
+                done;
+                break;;
+            -*) showUsage; yell "ERROR: Unrecognized option."; exit 1;; # Display usage
+           *) showUsage; yell "ERROR: Unrecognized argument."; exit 1;; # Handle unrecognized options. See [1].
        esac
        shift
     done
@@ -186,12 +201,14 @@ processArgs() {
 #==BEGIN sample code==
 processArgs "$@";
 yell "DEBUG:Provided arguments..:""$*" 
-yell "DEBUG:opVerbose...........:$opVerbose";
-yell "DEBUG:pathDirOut1.........:$pathDirOut1";
-yell "DEBUG:pathFileOut1........:$pathFileOut1";
-yell "DEBUG:pathDirIn1..........:$pathDirIn1";
-yell "DEBUG:pathFileIn1.........:$pathFileIn1";
-yell "DEBUG:opFileOut1_overwrite:$opFileOut1_overwrite";
+yell "DEBUG:opVerbose...........:${opVerbose:-<unset>}";
+yell "DEBUG:pathDirOut1.........:${pathDirOut1:-<unset>}";
+yell "DEBUG:pathFileOut1........:${pathFileOut1:-<unset>}";
+yell "DEBUG:pathDirIn1..........:${pathDirIn1:-<unset>}";
+yell "DEBUG:pathFileIn1.........:${pathFileIn1:-<unset>}";
+yell "DEBUG:opFileOut1_overwrite:${opFileOut1_overwrite:-<unset>}";
+yell "DEBUG:arrayPosArgs........:$(if [[ -v arrayPosArgs ]]; then declare -p arrayPosArgs; else printf "<unset>"; fi )";
+#yell "DEBUG:arrayPosArgs........:${arrayPosArgs[*]}";
 #==END sample code==
 
 # Author: Steven Baltaktei Sandoval