Browse Source

Add functions to find and dereference plugin variables

Alois Mahdal 5 years ago
parent
commit
3021e26330
2 changed files with 41 additions and 0 deletions
  1. 39
    0
      src/include-bash/sfpi.sh
  2. 2
    0
      tests/shellfu_api/oracle/functions.stdout

+ 39
- 0
src/include-bash/sfpi.sh View File

122
     shellfu import "$mod"
122
     shellfu import "$mod"
123
 }
123
 }
124
 
124
 
125
+sfpi__varname() {
126
+    #
127
+    # Print name of plugin $1 variable $2
128
+    #
129
+    # Note that the variables are assumed to be named in ALL_CAPS,
130
+    # so prefix is converted accordingly (not the variable name,
131
+    # though).
132
+    #
133
+    # Example:
134
+    #
135
+    #     SFPI__PREFIX=foo
136
+    #     sfpi__varname bar BAZ     # prints 'FOO_BAR__BAZ'
137
+    #
138
+    __sfpi__ckpfx
139
+    local plg=$1
140
+    local var=$2
141
+    echo "${SFPI__PREFIX^^}_${plg^^}__$var"
142
+}
143
+
144
+sfpi__varvalue() {
145
+    #
146
+    # Print value of plugin $1 variable $2
147
+    #
148
+    # Note that the variables are assumed to be named in ALL_CAPS,
149
+    # so prefix is converted accordingly (not the variable name,
150
+    # though).
151
+    #
152
+    # Example:
153
+    #
154
+    #     SFPI__PREFIX=foo
155
+    #     sfpi__varvalue bar BAZ    # prints value of $FOO_BAR__BAZ
156
+    #
157
+    __sfpi__ckpfx
158
+    local plg=$1
159
+    local var=$2
160
+    local varname="${SFPI__PREFIX^^}_${plg^^}__$var"
161
+    echo "${!varname}"
162
+}
163
+
125
 sfpi__funname() {
164
 sfpi__funname() {
126
     #
165
     #
127
     # Print name of plugin $1 function $2
166
     # Print name of plugin $1 function $2

+ 2
- 0
tests/shellfu_api/oracle/functions.stdout View File

101
 sfpi:sfpi__ls
101
 sfpi:sfpi__ls
102
 sfpi:sfpi__ls_all
102
 sfpi:sfpi__ls_all
103
 sfpi:sfpi__modname
103
 sfpi:sfpi__modname
104
+sfpi:sfpi__varname
105
+sfpi:sfpi__varvalue