Selaa lähdekoodia

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 vuotta sitten
vanhempi
commit
b88948ca3d
2 muutettua tiedostoa jossa 8 lisäystä ja 7 poistoa
  1. 3
    3
      src/bin/satcmd.skel
  2. 5
    4
      src/shellfu/saturnin.sh

+ 3
- 3
src/bin/satcmd.skel Näytä tiedosto

50
         *)              break;                          ;;
50
         *)              break;                          ;;
51
     esac done
51
     esac done
52
     subcommand="$1"; shift
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
     debug "\$*='$*'"
55
     debug "\$*='$*'"
56
     case "$subcommand" in
56
     case "$subcommand" in
57
         conf)               inigrep "$@"    ;;
57
         conf)               inigrep "$@"    ;;
60
         _lsfun)             shellfu-get lsfun ;;
60
         _lsfun)             shellfu-get lsfun ;;
61
         _lsmod)             shellfu-get lsmod ;;
61
         _lsmod)             shellfu-get lsmod ;;
62
         _ffrun)             ffrun "$@" ;;
62
         _ffrun)             ffrun "$@" ;;
63
-        *)                  saturnin__runsc "$@" ;;
63
+        *)                  saturnin__runsc "$subcommand" "$@" ;;
64
     esac
64
     esac
65
 }
65
 }
66
 
66
 

+ 5
- 4
src/shellfu/saturnin.sh Näytä tiedosto

55
     #
55
     #
56
     # Run subcommand $SATURNIN_SUBCOMMAND
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
     binpath+="$SATURNIN_LIBEXEC/"
60
     binpath+="$SATURNIN_LIBEXEC/"
60
-    binpath+="$SATURNIN_LIBEXEC_PREFIX$SATURNIN_SUBCOMMAND"
61
+    binpath+="$SATURNIN_LIBEXEC_PREFIX$subcommand"
61
     debug -v binpath
62
     debug -v binpath
62
     debug "\$*='$*'"
63
     debug "\$*='$*'"
63
     test -x "$binpath" || {
64
     test -x "$binpath" || {
64
-        warn "invalid sub-command: $SATURNIN_SUBCOMMAND"
65
+        warn "invalid sub-command: $subcommand"
65
         saturnin__help
66
         saturnin__help
66
         return "$SHELLFU_EXIT_USAGE"
67
         return "$SHELLFU_EXIT_USAGE"
67
     }
68
     }
68
-    "$binpath" "$@"
69
+    SATURNIN_SUBCOMMAND="$subcommand" "$binpath" "$@"
69
 }
70
 }
70
 
71
 
71
 saturnin__usage() {
72
 saturnin__usage() {