123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #!/bin/bash
-
- ffoo import exit
- ffoo import inigrep
- ffoo import pretty
-
- saturnin_help() {
- echo ""
- echo "built-in sub-commands:"
- echo ""
- echo " conf"
- echo " help"
- echo ""
- echo "installed sub-commands:"
- echo ""
- saturnin_lssc | sed -e 's/^/ /'
- return "$FFOO_EXIT_OK"
- }
-
- saturnin_lssc() {
- find "$SATURNIN_LIBEXEC" \
- -mindepth 1 \
- -maxdepth 1 \
- -executable \
- | sed -e 's/.*saturnin-//' \
- | sort
- }
-
- saturnin_runhook() {
- #
- # Run custom hook
- #
- local hname="$1"
- local hook_code
- test -n "$SATURNIN_SUBCOMMAND" || {
- warn "unknown subcommand, ignoring hook: $hname"
- return 0
- }
- hook_code="$(inigrep -j -p hook.$SATURNIN_SUBCOMMAND.$hname)"
- debug -v SATURNIN_SUBCOMMAND hook_code hname
- bash -n <<<"$hook_code" || {
- warn "syntax errors, ignoring hook: $hname"
- return 0
- }
- eval "$hook_code"
- }
-
- saturnin_runsc() {
- local sc_es=0 # future exit (return) status
- local lexpath="$SATURNIN_LIBEXEC/saturnin-$SATURNIN_SUBCOMMAND"
- debug -v lexpath
- debug "\$*='$*'"
- test -x "$lexpath" || {
- warn "invalid sub-command: $SATURNIN_SUBCOMMAND"
- saturnin_help
- return $FFOO_EXIT_USAGE
- }
- "$lexpath" "$@"
- }
-
- saturnin_wraphook() {
- #
- # Wrap command "$@" in hooks
- #
- # Run pre hook, then "$@", then post hook. Always exit
- # with status of "$@", even if hooks fail. Ignore
- # post-hook if "$@" failed.
- #
- local es=0
- saturnin_runhook pre
- "$@" || return $?
- es=$?
- saturnin_runhook post
- return $es
- }
|