Browse Source

Avoid exporting SATURNIN_SUBCOMMAND directly

Scripts may need it (eg. if using `saturnin__runhook()`) but exporting
it in the middle of main script makes it harder to see the scope
clearly and also is ugly.

Tweak the saturnin__runsc syntax so that it's not dependent on this
being global and export the SATURNIN_SUBCOMMAND only for the actual
subcommand binary call.
Alois Mahdal 8 years ago
parent
commit
b88948ca3d
2 changed files with 8 additions and 7 deletions
  1. 3
    3
      src/bin/satcmd.skel
  2. 5
    4
      src/shellfu/saturnin.sh

+ 3
- 3
src/bin/satcmd.skel View File

@@ -50,8 +50,8 @@ main() {
50 50
         *)              break;                          ;;
51 51
     esac done
52 52
     subcommand="$1"; shift
53
-    export SATURNIN_SUBCOMMAND="$subcommand"
54
-    debug -v SHELLFU_PATH SATURNIN_LIBEXEC SHELLFU_INIGREP_PATH SATURNIN_SUBCOMMAND
53
+    debug -v subcommand
54
+    debug -v SHELLFU_PATH SATURNIN_LIBEXEC SHELLFU_INIGREP_PATH
55 55
     debug "\$*='$*'"
56 56
     case "$subcommand" in
57 57
         conf)               inigrep "$@"    ;;
@@ -60,7 +60,7 @@ main() {
60 60
         _lsfun)             shellfu-get lsfun ;;
61 61
         _lsmod)             shellfu-get lsmod ;;
62 62
         _ffrun)             ffrun "$@" ;;
63
-        *)                  saturnin__runsc "$@" ;;
63
+        *)                  saturnin__runsc "$subcommand" "$@" ;;
64 64
     esac
65 65
 }
66 66
 

+ 5
- 4
src/shellfu/saturnin.sh View File

@@ -55,17 +55,18 @@ saturnin__runsc() {
55 55
     #
56 56
     # Run subcommand $SATURNIN_SUBCOMMAND
57 57
     #
58
-    local binpath   # path to subconnand's binary
58
+    local subcommand="$1"; shift
59
+    local binpath   # path to subcommand's binary
59 60
     binpath+="$SATURNIN_LIBEXEC/"
60
-    binpath+="$SATURNIN_LIBEXEC_PREFIX$SATURNIN_SUBCOMMAND"
61
+    binpath+="$SATURNIN_LIBEXEC_PREFIX$subcommand"
61 62
     debug -v binpath
62 63
     debug "\$*='$*'"
63 64
     test -x "$binpath" || {
64
-        warn "invalid sub-command: $SATURNIN_SUBCOMMAND"
65
+        warn "invalid sub-command: $subcommand"
65 66
         saturnin__help
66 67
         return "$SHELLFU_EXIT_USAGE"
67 68
     }
68
-    "$binpath" "$@"
69
+    SATURNIN_SUBCOMMAND="$subcommand" "$binpath" "$@"
69 70
 }
70 71
 
71 72
 saturnin__usage() {