Add options to configure logging

This commit is contained in:
Rezart Qelibari
2022-02-12 19:57:36 +01:00
parent 4eb51e34a7
commit 216cd329c0
2 changed files with 45 additions and 0 deletions

View File

@@ -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

View File

@@ -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