Parcourir la source

Enable reloading modules

Useful for modules like pretty.sh so that they can benefit from safety and
simplicity of having default but app can still reload it.

Note that in most cases using sfpi is cleaner and does not need
reloading, but pretty.sh is using dumb way of loading.
Alois Mahdal il y a 4 ans
Parent
révision
e96616b77e
1 fichiers modifiés avec 13 ajouts et 0 suppressions
  1. 13
    0
      src/shellfu.sh.skel

+ 13
- 0
src/shellfu.sh.skel Voir le fichier

@@ -173,6 +173,19 @@ shellfu() {
173 173
                 shellfu __die "cannot import module: $mname"
174 174
             fi
175 175
             ;;
176
+        reload)
177
+            #
178
+            # Reload module named $1 (unsafe!)
179
+            #
180
+            local mname=$1
181
+            shellfu _is_imported "$mname" || {
182
+                shellfu __warn "cannot reload; not imported yet: $mname"
183
+                return 2
184
+            }
185
+            if ! shellfu _do_import "$mname"; then
186
+                shellfu __die "cannot reload module: $mname"
187
+            fi
188
+            ;;
176 189
         try_import)
177 190
             #
178 191
             # Try if module $1 could be imported