From 99086e69fb7a3b5858ca1ee369ee1938de2d08eb Mon Sep 17 00:00:00 2001 From: Nikolaos Kakouros <nkak@kth.se> Date: Fri, 29 Jan 2021 18:33:43 +0100 Subject: [PATCH] wip --- headstart-core.bash | 36 ++++++++++++++++++------------------ headstart-load-libs.bash | 14 -------------- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/headstart-core.bash b/headstart-core.bash index 1e592e3..16e3dd3 100644 --- a/headstart-core.bash +++ b/headstart-core.bash @@ -69,6 +69,7 @@ core_get_installed_version core_parse_project_config function headstart() { + local trace=false local debug=false local verbosity='' local -a rest @@ -78,7 +79,10 @@ function headstart() { while [[ "$#" -gt 0 ]]; do case "$1" in - -d | --debug) + -d | --trace) + trace=true + ;; + -dd | --debug) debug=true ;; -v*) @@ -100,6 +104,19 @@ function headstart() { shift done + # This was originally in headstart-load-libs (as all uses of `import`) but + # was moved here in order to put the trace behind the `-d` cli option. + if [[ "$trace" == 'true' && "${_GO_BATS_DIR-unset}" == 'unset' ]]; then + import util/exception + fi + # When we are testing the project's code, we want for instance to check that + # a function returns with a specific code in case of an error. In these cases, + # we do not want this error code to trigger the stack trace that the + # `util/exception` code prints as it would pollute the test output. So, we + # only import this module when not testing. To check if we are in test mode or + # not, we check the existence of a variable that is set only when testing. We + # chose randomly `_GO_BATS_DIR` that is set in `devel/test`. + . "$_GO_USE_MODULES" 'installation' 'aliases' if [[ "$go_early" == 'true' ]]; then @@ -150,22 +167,5 @@ function headstart() { core_check_upgrades - # TODO don't rely on this returning empty strings. When first installing, - # `core bootstrap` will execute this returning nothing. Instead handle that - # case better and have the function return an error code if it doesn't find - # what it needs. - if [[ "${rest[*]}" != '' && "${rest[0]}" == 'core' ]]; then - if [[ "${#rest[*]}" -ge 2 && "${rest[1]}" == 'bootstrap' ]]; then - @go "${rest[@]}" - return - fi - fi - - if [[ "${rest[*]}" == '' ]]; then - trap - ERR - @go - return - fi - @go "${rest[@]}" } diff --git a/headstart-load-libs.bash b/headstart-load-libs.bash index f739a10..c86cf88 100644 --- a/headstart-load-libs.bash +++ b/headstart-load-libs.bash @@ -51,20 +51,6 @@ import util/tryCatch import util/variable import util/namedParameters -# TODO do I need this? -# if [[ "${_GO_BATS_DIR-unset}" == 'unset' ]]; then -import util/exception -# fi -# <<-CODE-NOTE: When we are testing the project's code, we want for instance to -# check that a function returns with a specific code in case of -# an error. In these cases, we do not want this error code to -# trigger the stack trace that the `util/exception` code prints -# as it would pollute the test output. So, we only import this -# module when not testing. To check if we are in test mode or -# not, we check the existence of a variable that is set only when -# testing. We chose randomly `_GO_BATS_DIR` that is set in -# `devel/test`. - # CUSTOM LIBS # =========== # TODO source directly due to variable scoping -- GitLab