]> git.corax.cc Git - toolbox/commitdiff
include/opt: Remove unnecessary array __opt_long
authorMatthias Kruk <m@m10k.eu>
Thu, 11 Aug 2022 17:48:34 +0000 (02:48 +0900)
committerMatthias Kruk <m@m10k.eu>
Thu, 11 Aug 2022 17:48:34 +0000 (02:48 +0900)
The data that is stored in opt's __opt_long array is a subset of
the data stored in __opt_map. The operations that the module does
on __opt_long might just as well be performed on __opt_map without
affecting the behavior of the module.

This commit removes the __opt_long array from the module and
changes the affected functions to use __opt_map instead.

include/opt.sh

index d9c596a1192ddef74637fc4da4ef6a686dbab83b..f2bb6adadcf4b57de3cf05253bdab870816254f4 100644 (file)
@@ -30,7 +30,6 @@ __init() {
        )
 
        declare -Axg __opt_short
-       declare -Axg __opt_long
        declare -Axg __opt_desc
        declare -Axg __opt_flags
        declare -Axg __opt_value
@@ -114,7 +113,6 @@ opt_add_arg() {
        fi
 
        __opt_short["$long"]="$short"
-       __opt_long["$short"]="$long"
        __opt_flags["$long"]="$parsed_flags"
        __opt_desc["$long"]="$desc"
        __opt_regex["$long"]="$regex"
@@ -151,7 +149,7 @@ opt_print_help() {
                local long
                local desc
 
-               long="${__opt_long[$short]}"
+               long="${__opt_map[-$short]}"
                desc="${__opt_desc[$long]}"
 
                printf "\t-%s\t--%s\t%s\n" \