From ead076a8e0092e420a446dc41d7a9562c32a79ed Mon Sep 17 00:00:00 2001 From: Rezart Qelibari Date: Thu, 17 Feb 2022 15:48:45 +0100 Subject: [PATCH] Call getUsage after checking prerequisites in lib --- modules/01-system-settings.sh | 16 +++++++++++----- modules/lib.sh | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/01-system-settings.sh b/modules/01-system-settings.sh index f7415ed..377118f 100755 --- a/modules/01-system-settings.sh +++ b/modules/01-system-settings.sh @@ -100,16 +100,15 @@ function configure_system() { launchctl config user umask 027 } -if [[ "${ZSH_EVAL_CONTEXT}" == toplevel ]]; then - test -f "${ASTZWEIG_MACOS_SYSTEM_LIB}" || { echo 'This module requires macos-system library. Please run again with macos-system library provieded as a path in ASTZWEIG_MACOS_SYSTEM_LIB env variable.'; return 10 } - source "${ASTZWEIG_MACOS_SYSTEM_LIB}" - module_main "$@" <<- USAGE +function getUsage() { + local text + read -r -d '' text <<- USAGE Usage: $0 show-questions $0 [-v] [-d FILE] --hostname NAME --timezone ZONE Set energy, basic network and host preferences. - + Options: --hostname NAME Set NAME as current host's host name. --timezone ZONE Set ZONE as current host's timezone [default: Europe/Berlin]. @@ -120,4 +119,11 @@ if [[ "${ZSH_EVAL_CONTEXT}" == toplevel ]]; then Copyright (C) 2022 Rezart Qelibari, Astzweig GmbH & Co. KG License EUPL-1.2. There is NO WARRANTY, to the extent permitted by law. USAGE + print ${text} +} + +if [[ "${ZSH_EVAL_CONTEXT}" == toplevel ]]; then + test -f "${ASTZWEIG_MACOS_SYSTEM_LIB}" || { echo 'This module requires macos-system library. Please run again with macos-system library provieded as a path in ASTZWEIG_MACOS_SYSTEM_LIB env variable.'; return 10 } + source "${ASTZWEIG_MACOS_SYSTEM_LIB}" + module_main "$@" fi diff --git a/modules/lib.sh b/modules/lib.sh index ce46350..b35dbcb 100644 --- a/modules/lib.sh +++ b/modules/lib.sh @@ -37,7 +37,7 @@ function showQuestions() { function module_main() { autoloadZShLib || return checkPrerequisites || return - eval "`docopts -f -V - -h - : "$@"`" + eval "`getUsage | docopts -f -V - -h - : "$@"`" [ $# -le 1 ] && return configureLogging [ "${show_questions}" = true ] && { showQuestions; return }