]> git.corax.cc Git - toolbox/commitdiff
include/opt: Remember arguments passed to opt_parse()
authorMatthias Kruk <m@m10k.eu>
Thu, 15 Apr 2021 13:28:08 +0000 (22:28 +0900)
committerMatthias Kruk <m@m10k.eu>
Thu, 15 Apr 2021 13:28:08 +0000 (22:28 +0900)
To allow the user to distinguish running instances of a script, it is
necessary to present the arguments that an instance was started with.
The most logical place to remember such information is inside the opt
module. Therefore, this commit adds the opt_get_argv() function, which
allows the caller to retrieve the arguments that were passed to the
opt_parse() function.

include/opt.sh

index 7af5be310900c60340571684a14a9fdc2a18ae29..d04e3e88064c3fd7b6e5da4c2d37f0fc7636866b 100644 (file)
@@ -108,6 +108,8 @@ opt_parse() {
        local opt
        local i
 
+       declare -argx __opt_argv=("$@")
+
        for (( i = 1; i <= $#; i++ )); do
                local param
                local long
@@ -169,3 +171,8 @@ opt_get() {
        echo "${__opt_value[$long]}"
        return 0
 }
+
+opt_get_argv() {
+       echo "${__opt_argv[@]}"
+       return 0
+}