From 216cd329c0253c907aa8abfbf50cbf9d7ecabc13 Mon Sep 17 00:00:00 2001 From: Rezart Qelibari Date: Sat, 12 Feb 2022 19:57:36 +0100 Subject: [PATCH] Add options to configure logging --- install.sh | 10 ++++++++++ spec/configureLogging_spec.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 spec/configureLogging_spec.sh diff --git a/install.sh b/install.sh index 8ecabef..9432225 100755 --- a/install.sh +++ b/install.sh @@ -15,6 +15,13 @@ function autoloadZShLib() { autoload -Uz "${funcNames[@]}" } +function configureLogging() { + local output=tostdout level=info + [ -n "${logfile}" ] && output="${logfile}" + [ "${verbose}" = true ] && level=debug + lop setoutput -l "${level}" "${output}" +} + function filterModules() { if [ "${#module}" -eq 0 ]; then modulesToInstall=("${allModules[@]}") @@ -211,6 +218,8 @@ function main() { -l, --list List modules that are going to be installed and exit without installation. Modules are printed in minimal but still distinct paths. + -d FILE, --logfile FILE Print log message to logfile instead of stdout. + -v, --verbose Be more verbose. --config-only PATH Ask module questions, generate config at PATH and exit. Useful for subsequent runs with c option. Any file at PATH will be overwritten. @@ -223,6 +232,7 @@ function main() { local -A answers ensureDocopts autoloadZShLib + configureLogging loadModules askNecessaryQuestions [ -z "${config_only}" ] || return 0 diff --git a/spec/configureLogging_spec.sh b/spec/configureLogging_spec.sh new file mode 100644 index 0000000..e6ac7d3 --- /dev/null +++ b/spec/configureLogging_spec.sh @@ -0,0 +1,35 @@ +Describe 'configureLogging' + Include ./install.sh + args=() + lop() { args=("$@") } + setup() { args=() } + BeforeEach setup + + It 'configures lop with standard args' + When call configureLogging + The variable 'args[3]' should eq 'info' + The variable 'args[4]' should eq 'tostdout' + End + + It 'configures lop output mode' + logfile="/some/path with spaces/to/file.txt" + When call configureLogging + The variable 'args[3]' should eq 'info' + The variable 'args[4]' should eq "${logfile}" + End + + It 'configures lop log level' + verbose=true + When call configureLogging + The variable 'args[3]' should eq 'debug' + The variable 'args[4]' should eq 'tostdout' + End + + It 'configures lop output mode and log level' + logfile="/some/path with spaces/to/file.txt" + verbose=true + When call configureLogging + The variable 'args[3]' should eq 'debug' + The variable 'args[4]' should eq "${logfile}" + End +End