Display help message if mandatory arguments are missing

This commit is contained in:
Jérémy Lecour 2020-04-25 10:30:21 +02:00 committed by Jérémy Lecour
parent 1cbb982d02
commit 807dd44408
2 changed files with 17 additions and 2 deletions

View file

@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
* Display help message if mandatory arguments are missing.
### Deprecated ### Deprecated
### Removed ### Removed

17
bkctld
View file

@ -52,17 +52,30 @@ case "${subcommand}" in
;; ;;
"init" | "is-on") "init" | "is-on")
jail_name="${2:-}" jail_name="${2:-}"
"${LIBDIR}/bkctld-${subcommand}" "${jail_name}" if [ -z "${jail_name}" ]; then
"${LIBDIR}/bkctld-help"
exit 1
else
"${LIBDIR}/bkctld-${subcommand}" "${jail_name}"
fi
;; ;;
"key" | "port" | "ip") "key" | "port" | "ip")
jail_name="${2:-}" jail_name="${2:-}"
option="${3:-}" option="${3:-}"
"${LIBDIR}/bkctld-${subcommand}" "${jail_name}" "${option}" if [ "${jail_name}" = "all" ] || [ -z "${jail_name}" ]; then
"${LIBDIR}/bkctld-help"
exit 1
else
"${LIBDIR}/bkctld-${subcommand}" "${jail_name}" "${option}"
fi
;; ;;
"start" | "stop" | "reload" | "restart" | "sync" | "update" | "remove" | "firewall") "start" | "stop" | "reload" | "restart" | "sync" | "update" | "remove" | "firewall")
jail_name="${2:-}" 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}"
elif [ -z "${jail_name}" ]; then
"${LIBDIR}/bkctld-help"
exit 1
else else
"${LIBDIR}/bkctld-${subcommand}" "${jail_name}" "${LIBDIR}/bkctld-${subcommand}" "${jail_name}"
fi fi