subcommand options are examined in their respective context

This commit is contained in:
Jérémy Lecour 2020-04-18 10:28:06 +02:00 committed by Jérémy Lecour
parent 14c4b63e69
commit 4c9cbf976e

16
bkctld
View file

@ -35,24 +35,21 @@ fi
. "${LIBDIR}/includes" . "${LIBDIR}/includes"
subcommand="${1:-}" subcommand="${1:-}"
jail_name="${2:-}"
option="${3:-}"
if [ ! -x "${LIBDIR}/bkctld-${subcommand}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
case "${subcommand}" in case "${subcommand}" in
"inc" | "rm" | "check" | "stats" | "help" | "list") "inc" | "rm" | "check" | "stats" | "help" | "list")
"${LIBDIR}/bkctld-${subcommand}" "${LIBDIR}/bkctld-${subcommand}"
;; ;;
"init" | "is-on") "init" | "is-on")
jail_name="${2:-}"
"${LIBDIR}/bkctld-${subcommand}" "${jail_name}" "${LIBDIR}/bkctld-${subcommand}" "${jail_name}"
;; ;;
"key" | "port" | "ip") "key" | "port" | "ip")
jail_name="${2:-}"
option="${3:-}"
"${LIBDIR}/bkctld-${subcommand}" "${jail_name}" "${option}" "${LIBDIR}/bkctld-${subcommand}" "${jail_name}" "${option}"
;; ;;
"start" | "stop" | "reload" | "restart" | "sync" | "update" | "remove" | "firewall") "start" | "stop" | "reload" | "restart" | "sync" | "update" | "remove" | "firewall")
jail_name="${2:-}"
if [ "${jail_name}" = "all" ]; then if [ "${jail_name}" = "all" ]; then
"${LIBDIR}/bkctld-list" | xargs --no-run-if-empty --max-args=1 --max-procs=0 "${LIBDIR}/bkctld-${subcommand}" "${LIBDIR}/bkctld-list" | xargs --no-run-if-empty --max-args=1 --max-procs=0 "${LIBDIR}/bkctld-${subcommand}"
else else
@ -60,10 +57,15 @@ case "${subcommand}" in
fi fi
;; ;;
"status") "status")
jail_name="${2:-}"
if [ "${jail_name}" = "all" ] || [ -z "${jail_name}" ]; then if [ "${jail_name}" = "all" ] || [ -z "${jail_name}" ]; then
"${LIBDIR}/bkctld-list" | xargs --no-run-if-empty --max-args=1 "${LIBDIR}/bkctld-${subcommand}" "${LIBDIR}/bkctld-list" | xargs --no-run-if-empty --max-args=1 "${LIBDIR}/bkctld-${subcommand}"
else else
"${LIBDIR}/bkctld-${subcommand}" "${jail_name}" "${LIBDIR}/bkctld-${subcommand}" "${jail_name}"
fi fi
;; ;;
*)
"${LIBDIR}/bkctld-help"
exit 1
;;
esac esac