瀏覽代碼

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 4 年之前
父節點
當前提交
e96616b77e
共有 1 個文件被更改,包括 13 次插入0 次删除
  1. 13
    0
      src/shellfu.sh.skel

+ 13
- 0
src/shellfu.sh.skel 查看文件

@@ -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