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
* Display help message if mandatory arguments are missing.
### Deprecated
### Removed

17
bkctld
View File

@ -52,17 +52,30 @@ case "${subcommand}" in
;;
"init" | "is-on")
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")
jail_name="${2:-}"
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")
jail_name="${2:-}"
if [ "${jail_name}" = "all" ]; then
"${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
"${LIBDIR}/bkctld-${subcommand}" "${jail_name}"
fi