Pass arg $0 to module_main

This commit is contained in:
Rezart Qelibari
2022-02-17 15:58:52 +01:00
parent ead076a8e0
commit 90758b2fdd
2 changed files with 9 additions and 7 deletions

View File

@@ -101,11 +101,11 @@ function configure_system() {
}
function getUsage() {
local text
local cmdName=$1 text=''
read -r -d '' text <<- USAGE
Usage:
$0 show-questions
$0 [-v] [-d FILE] --hostname NAME --timezone ZONE
$cmdName show-questions
$cmdName [-v] [-d FILE] --hostname NAME --timezone ZONE
Set energy, basic network and host preferences.
@@ -115,7 +115,7 @@ function getUsage() {
-d FILE, --logfile FILE Print log message to logfile instead of stdout.
-v, --verbose Be more verbose.
----
$0 0.1.0
$cmdName 0.1.0
Copyright (C) 2022 Rezart Qelibari, Astzweig GmbH & Co. KG
License EUPL-1.2. There is NO WARRANTY, to the extent permitted by law.
USAGE
@@ -125,5 +125,5 @@ function getUsage() {
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 "$@"
module_main $0 "$@"
fi

View File

@@ -35,10 +35,12 @@ function showQuestions() {
}
function module_main() {
local cmdName=${1:t}
shift
autoloadZShLib || return
checkPrerequisites || return
eval "`getUsage | docopts -f -V - -h - : "$@"`"
[ $# -le 1 ] && return
eval "`getUsage $cmdName | docopts -f -V - -h - : "$@"`"
[ $# -lt 1 ] && return
configureLogging
[ "${show_questions}" = true ] && { showQuestions; return }
configure_system