From 4ecbd12017c5d4239d96d893678d8a8f64723a6f Mon Sep 17 00:00:00 2001 From: robstoll <5557885+robstoll@users.noreply.github.com> Date: Mon, 21 Oct 2024 04:07:15 +0000 Subject: [PATCH] update files of remote tegonal-scripts to version v3.5.0 via gt --- .gt/remotes/tegonal-scripts/pulled.tsv | 38 +++++++++---------- .../src/ci/install-shellcheck.sh | 4 +- lib/tegonal-scripts/src/qa/run-shellcheck.sh | 4 +- lib/tegonal-scripts/src/setup.sh | 2 +- .../src/utility/array-utils.sh | 12 +++--- lib/tegonal-scripts/src/utility/ask.sh | 10 ++--- lib/tegonal-scripts/src/utility/checks.sh | 33 +++++++++++----- lib/tegonal-scripts/src/utility/git-utils.sh | 21 ++++++---- lib/tegonal-scripts/src/utility/gpg-utils.sh | 2 +- lib/tegonal-scripts/src/utility/io.sh | 10 ++--- lib/tegonal-scripts/src/utility/log.sh | 18 ++++----- lib/tegonal-scripts/src/utility/parse-args.sh | 25 +++++++----- .../src/utility/parse-commands.sh | 8 ++-- .../src/utility/parse-fn-args.sh | 12 +++--- .../src/utility/parse-utils.sh | 4 +- .../src/utility/recursive-declare-p.sh | 2 +- .../src/utility/replace-help-snippet.sh | 2 +- .../src/utility/replace-snippet.sh | 2 +- .../src/utility/source-once.sh | 6 +-- .../src/utility/update-bash-docu.sh | 2 +- 20 files changed, 124 insertions(+), 93 deletions(-) diff --git a/.gt/remotes/tegonal-scripts/pulled.tsv b/.gt/remotes/tegonal-scripts/pulled.tsv index a458626..c369664 100644 --- a/.gt/remotes/tegonal-scripts/pulled.tsv +++ b/.gt/remotes/tegonal-scripts/pulled.tsv @@ -1,21 +1,21 @@ #@ Version: 1.0.0 tag file relativeTarget sha512 -v3.2.0 src/setup.sh ../lib/tegonal-scripts/src/setup.sh f6221b322efb57a8e595c4d033e18ee3d4ba7b373f549fc1e608401a2976ac03e09f4f033787f3d25896d7cf9447edf074f558259c7813df65792440bc472e09 -v3.2.0 src/utility/io.sh ../lib/tegonal-scripts/src/utility/io.sh 701867a847119f4da16af5cc75c1261bf53d2a7e0d61c289e5b1358e28aba34d2ab0e964adb3bc18d0c249ed869c29440463a5b8aa70376a47d42293813e1549 -v3.2.0 src/utility/array-utils.sh ../lib/tegonal-scripts/src/utility/array-utils.sh 34e6549d3208d4bee23e28a9c81b7f6774280a5a9afd5759fc5ace8161d35a87acfec707b75d447a427e6f4f3ad14d6ba48529a92f7a0be91526e456bc2d85a1 -v3.2.0 src/utility/parse-utils.sh ../lib/tegonal-scripts/src/utility/parse-utils.sh 31c842882e85e4ed9192b31f042a8348229776622d01d6c15f49caee4faf49da74c7d50f379c532fc4998da52cedd51a36e92b432f71908cd31ce84652653918 -v3.2.0 src/utility/git-utils.sh ../lib/tegonal-scripts/src/utility/git-utils.sh 5766b484335d71b7889e0060905295eb3b43acc1ea102d23d859eb83537940f0165c5a29d818d8ba8017e9a46824a2b11328e13bdc8160d31699ebfa0b4e809a -v3.2.0 src/utility/gpg-utils.sh ../lib/tegonal-scripts/src/utility/gpg-utils.sh 57dc45a171642bd8925f73eb44c2fbccbf9084e0c95a868d1204b2d7b5d330f9b549db2af5ba9907dae7f0852ece39ab1656274ac383cebd0abbb0d12cee1eff -v3.2.0 src/utility/log.sh ../lib/tegonal-scripts/src/utility/log.sh 3ff775eb686499bf75f497c7071fbe0c64c0b2a129318a7f0010870b9b4328848aa029d98a2d1cc58dab5b15834e5e689a2efbec981e9898eb5af68c729e49df -v3.2.0 src/utility/parse-fn-args.sh ../lib/tegonal-scripts/src/utility/parse-fn-args.sh 9d93c8fb0bea1109a4cf51438eda04c70b2479e51ff05eef529e2715405c054339620117d3164876e6f325612be641da6653fce9435a637b3768b01a89c5c9d6 -v3.2.0 src/utility/update-bash-docu.sh ../lib/tegonal-scripts/src/utility/update-bash-docu.sh 8f564cf2946d4ab4a8089331990ddfc24f7194dbe1d4377505faced56d6a4e60bab0c3dfbaf39662676f49d36bfa9f79594d9177ba2c9ec46f825d332529516b -v3.2.0 src/utility/parse-args.sh ../lib/tegonal-scripts/src/utility/parse-args.sh 7fa58fc83d65ed11393f2ee688aedc5d133571194dc6c3bb7b053133154f53d8909cf9f732d619d70d17d6cc37d2f392ae1b0d6d055602893b74cbcde06425e2 -v3.2.0 src/utility/checks.sh ../lib/tegonal-scripts/src/utility/checks.sh 5d2482992c3c0e562faba718b3946cdb8b58cdf5fc5d6ece6a5a4a0050262ec80ea2f95b6f6b927940298171747adcda511325991c6a530d8af8c4a5a454faa7 -v3.2.0 src/utility/parse-commands.sh ../lib/tegonal-scripts/src/utility/parse-commands.sh 6ac7234f74f545942cab445ea90c157203075839abfd20191bfec266d6c15fbfac681523543fb61ccf5f1dbc16cc3125c5a86ec9daf1d763ef2af634acde506e -v3.2.0 src/utility/replace-snippet.sh ../lib/tegonal-scripts/src/utility/replace-snippet.sh 861813fee3650a32ad89548f4a816eeaa85b713dd146791d4afe342af30cc1bded27f620fae8702886c6fd58a00c9cc8da9b3254cefcf3155d748a021272c32e -v3.2.0 src/utility/ask.sh ../lib/tegonal-scripts/src/utility/ask.sh e7dc9cf595aa46cb1593db997e6079546371e5b9e832a5233301a2d3d73378a579de47ed1742e42aa845a932ab5e6758208f2d2c505263ee8eecc2c164f72d6b -v3.2.0 src/utility/replace-help-snippet.sh ../lib/tegonal-scripts/src/utility/replace-help-snippet.sh f0b90b8ed4bdea02609ca71df547d5853e315fc30b7e2ea8aaeb20ffcb5da910045d8cdde213137350e8f26d529032f626b558d81cc436c31b22467ef1cb3dfd -v3.2.0 src/utility/source-once.sh ../lib/tegonal-scripts/src/utility/source-once.sh 6b6688d85a5a0c591c73d2ef32a0b896266ceb6af7cea0f06afd8a645b46b2e38abf1eaa2efa444a06382ef0c170de6a2ba2e14062fba0bfa0d384198e0ac1a2 -v3.2.0 src/utility/recursive-declare-p.sh ../lib/tegonal-scripts/src/utility/recursive-declare-p.sh 10a0d54232712ca7dd56297d7022194f6fcadf564c458d3ff04a15d8539989d8d727db9e903e0a062e0cd75667b71cf8f56444d9116f37664505ac19610ce2fb -v3.2.0 src/ci/install-shellcheck.sh ../lib/tegonal-scripts/src/ci/install-shellcheck.sh 628dafc9ab0a44bd588785631f3d1f58f79f8764d3d628796fdb913d50cbf5991baa2d5df3d3b62d0d93ae41eef6d36f547a32186438f42c1430758e089f711e -v3.2.0 src/qa/run-shellcheck.sh ../lib/tegonal-scripts/src/qa/run-shellcheck.sh e717ded82bd1545d355a101486a8e746786a224c6110ba0b8451b9754822901f2636320092cf813a55a082c45ae96943cf963c6261c361f2c753f646bb36aa98 +v3.5.0 src/setup.sh ../lib/tegonal-scripts/src/setup.sh c72440ceb9dfffca3feacb4d652f8b6ad1266277a1549b6271a47e1c0fdc0746994cf01a1a0335a95e1c7e93454a1fdade9007d7d2226f20e95e6f52ea0d0fa7 +v3.5.0 src/utility/io.sh ../lib/tegonal-scripts/src/utility/io.sh e905f8ec3c0ea6b5d3a3c3a295bab690cc2b9d42ec784d56ec525f24044490c216756e05f6d9312f6379821e3f7208d44990bd8c598e9b268f40cc933951dcc9 +v3.5.0 src/utility/array-utils.sh ../lib/tegonal-scripts/src/utility/array-utils.sh 357c47ad757cdd8be932f2c1b6c000c58e5b502fe1d19c921568d736355e04ff01b652b407a0f04664ccfc1c2cfbd8e0b3b8a695521ce0a3a88eb289c8cbaf38 +v3.5.0 src/utility/parse-utils.sh ../lib/tegonal-scripts/src/utility/parse-utils.sh 04164299e848f75681497284e5c9b358a62f98d213c60d9f2a576342f7a116a9b1a4acf6a591d1535dfc0351b2f656a3f8c4f838ec8e01611f94c3e0111e46d2 +v3.5.0 src/utility/git-utils.sh ../lib/tegonal-scripts/src/utility/git-utils.sh dcbf51d144a2e797df34862e495fcb1a8c0387990c7454158c40f5ebf38d1837a9c75fca09c5fa4ae88905b2d21ceafa3ee657bb6ab2cbc3924dea51e47393b3 +v3.5.0 src/utility/gpg-utils.sh ../lib/tegonal-scripts/src/utility/gpg-utils.sh ea15975b230cabcc1d75afea011270b4d5c03e2ea4dda8558bd2060b4a2b4f02d48022019c83b23d85f83fefc7de1a8a87318cda0af7e948c3912aa3d7cda8b7 +v3.5.0 src/utility/log.sh ../lib/tegonal-scripts/src/utility/log.sh 3fdea7b78d37c9424602c1d0ff90ff19b7e7d3674d8ad412777754221118851ebdab41c129fb9181110a3639a19712ebf81ed35d4b86314814a53d99bbb2b26f +v3.5.0 src/utility/parse-fn-args.sh ../lib/tegonal-scripts/src/utility/parse-fn-args.sh 64b8f1dac3ed9cf860719b40f6e9adfa973096a4754714de20bbb9f42ade1572a754eeea1495a12395529bd71f1d4b280e613a23d26edd7e5546486fe9b9cbb4 +v3.5.0 src/utility/update-bash-docu.sh ../lib/tegonal-scripts/src/utility/update-bash-docu.sh a2194e8afba6d70589d3f3aed954e303c956125746ddbdd97beaa0ef015d354ce08949c712cbb80e26a0da52399cb90d8551b9dc60ab2ac890c6d1e8b03318da +v3.5.0 src/utility/parse-args.sh ../lib/tegonal-scripts/src/utility/parse-args.sh 18a1b91f8e3aa6c61805ca8a9cf43ac87a817b61032297455aaff198a65b9d2fbfcb7bb3bdac9a940020129694ce2a7997d917e51413e8228dce4265df59a96a +v3.5.0 src/utility/checks.sh ../lib/tegonal-scripts/src/utility/checks.sh 1a25b07c8a19b93b5ca91582fb636e9273911fed455de2964a803ac09416201739bcd66eab39a94d9916f8d4a668c5c75bbd8f4b5bf6fb4fdc11b912d056b245 +v3.5.0 src/utility/parse-commands.sh ../lib/tegonal-scripts/src/utility/parse-commands.sh 9e2b1a685aa14c574e1421ba6e3155a112dc47c069a09d048ced9f22eb85b400c701239ae5c64f898c384df97d849a008925ca22b67cfba42e89a8c5fc09a16a +v3.5.0 src/utility/replace-snippet.sh ../lib/tegonal-scripts/src/utility/replace-snippet.sh 0eaf94a12decc88f3c905290da1b18d0037f6d9fb6908517d3d85ec48972e0ee0288e8de5e2b88fb36e4d24f5ebe8d9a5b819d0afe5c7f35ad778c41b1a3f1d5 +v3.5.0 src/utility/ask.sh ../lib/tegonal-scripts/src/utility/ask.sh 4678ad9224783ef52e49e6eb65c16eea902a1a22d28754fd70911b5bceb1810093e6942a57ed473c99a4ae8985b649b569444e16a549a80f102eff97a43d4691 +v3.5.0 src/utility/replace-help-snippet.sh ../lib/tegonal-scripts/src/utility/replace-help-snippet.sh 6fb6bd4aacc13cd02889b125642ceb0b7e3cf7032412d692f85fa412f9457873345aa49d53d98fefdd8056f84bc36d0dea4e8f1e6ee4d7adff3de67c23bccc40 +v3.5.0 src/utility/source-once.sh ../lib/tegonal-scripts/src/utility/source-once.sh f9464a208738c42754b316328586eb7a5c52cffddb57aa27ce15c4e67889667d4b7df6736a97df5ce0ca64ffe430151c6055f6e0cb53c0057f7111242895394c +v3.5.0 src/utility/recursive-declare-p.sh ../lib/tegonal-scripts/src/utility/recursive-declare-p.sh b48bd331c9d3300ab676e969fd8b51bffb409de15b5745f30a7f3867a1a14a50828c5f83e4bc104c5e481261508578903a579986b7e2b7b0f23fe0d5e1ead621 +v3.5.0 src/ci/install-shellcheck.sh ../lib/tegonal-scripts/src/ci/install-shellcheck.sh 5dd7f1e67ebe2c1c1ea2e51b6e42ace0cf9c2963781b873d223e279c0df03c64b2781bb67c2d8ad1630915f24145fda3a4ab965250be91f20f9cd0574654563e +v3.5.0 src/qa/run-shellcheck.sh ../lib/tegonal-scripts/src/qa/run-shellcheck.sh c4777d0e64ccfdfd96114227ca703668a9938d3c27cd7f931ef10b8eb7cd943c089dc1b83c4508c77fea275e656b0d9e548157b64f68fa55446a344443ef7cce diff --git a/lib/tegonal-scripts/src/ci/install-shellcheck.sh b/lib/tegonal-scripts/src/ci/install-shellcheck.sh index 4f5b8eb..4e12f8e 100755 --- a/lib/tegonal-scripts/src/ci/install-shellcheck.sh +++ b/lib/tegonal-scripts/src/ci/install-shellcheck.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # function which searches for *.sh files within defined paths (directories or a single *.sh) and @@ -20,7 +20,7 @@ # # jobs: # steps: -# - name: install shellcheck v0.10.0 +# - name: install shellcheck # run: ./lib/tegonal-scripts/src/ci/install-shellcheck.sh # # and most likely as well # - name: run shellcheck diff --git a/lib/tegonal-scripts/src/qa/run-shellcheck.sh b/lib/tegonal-scripts/src/qa/run-shellcheck.sh index cc2739b..c446cc0 100755 --- a/lib/tegonal-scripts/src/qa/run-shellcheck.sh +++ b/lib/tegonal-scripts/src/qa/run-shellcheck.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # function which searches for *.sh files within defined paths (directories or a single *.sh) and @@ -58,7 +58,7 @@ function runShellcheck() { fi local -rn runShellcheck_paths=$1 local -r sourcePath=$2 - shift 2 || die "could not shift by 2" + shift 2 || traceAndDie "could not shift by 2" exitIfArgIsNotArrayOrIsEmpty runShellcheck_paths 1 diff --git a/lib/tegonal-scripts/src/setup.sh b/lib/tegonal-scripts/src/setup.sh index 996d564..bcaa60f 100644 --- a/lib/tegonal-scripts/src/setup.sh +++ b/lib/tegonal-scripts/src/setup.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # script which should be sourced and sets up variables and functions for the scripts diff --git a/lib/tegonal-scripts/src/utility/array-utils.sh b/lib/tegonal-scripts/src/utility/array-utils.sh index b4f96ce..6beacb1 100644 --- a/lib/tegonal-scripts/src/utility/array-utils.sh +++ b/lib/tegonal-scripts/src/utility/array-utils.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # utility functions for dealing with arrays @@ -63,7 +63,7 @@ sourceOnce "$dir_of_tegonal_scripts/utility/checks.sh" joinByChar() { local IFS="$1" - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" echo "$*" } @@ -78,7 +78,7 @@ joinByString() { if (($# > 1)); then local separator="$1" local firstArg="$2" - shift 2 || die "could not shift by 2" + shift 2 || traceAndDie "could not shift by 2" printf "%s" "$firstArg" "${@/#/$separator}" fi } @@ -96,7 +96,7 @@ function arrFilter() { local -rn arrFilter_arrIn=$1 local -rn arrFilter_arrOut=$2 local -r predicate=$3 - shift 3 || die "could not shift by 3" + shift 3 || traceAndDie "could not shift by 3" exitIfArgIsNotFunction "$predicate" 3 @@ -127,7 +127,7 @@ function arrTakeEveryX() { local -rn arrFilterMod_arrOut=$2 local -ri modulo=$3 local -ri offset=$4 - shift 4 || die "could not shift by 4" + shift 4 || traceAndDie "could not shift by 4" # shellcheck disable=SC2317 # is passed by name to arrFilter function arrFilterMod_fn() { @@ -146,7 +146,7 @@ function arrStringEntryMaxLength() { exit 9 fi local -rn arrStringEntryMaxLength_arr=$1 - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" local -i i maxLength=0 arrLength="${#arrStringEntryMaxLength_arr[@]}" for ((i = 0; i < arrLength; ++i)); do diff --git a/lib/tegonal-scripts/src/utility/ask.sh b/lib/tegonal-scripts/src/utility/ask.sh index c6fd102..0dfce9d 100644 --- a/lib/tegonal-scripts/src/utility/ask.sh +++ b/lib/tegonal-scripts/src/utility/ask.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # Utility functions to ask the user something via input. @@ -55,7 +55,7 @@ function askYesOrNo() { exit 9 fi local -r question=$1 - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" local -r askYesOrNo_timeout=20 local answer='n' @@ -68,9 +68,9 @@ function askYesOrNo() { # shellcheck disable=SC2059 # the question itself can have %s thus we use it in the format string askWithTimeout "\033[0;36m$question\033[0m y/[n]:" "$askYesOrNo_timeout" askYesOrNo_noAnswerCallback answer "" "$@" - if [[ $answer == y ]] || [[ $answer == Y ]]; then + if [[ $answer == y ]] || [[ $answer == Y ]] || [[ $answer == yes ]]; then return 0 - elif [[ $answer == n ]] || [[ $answer == N ]]; then + elif [[ $answer == n ]] || [[ $answer == N ]] || [[ $answer == no ]]; then return 1 else logWarning "got \033[0;36m%s\033[0m as answer (instead of y for yes or n for no), interpreting it as a n, i.e. as a no" "$answer" @@ -99,7 +99,7 @@ function askWithTimeout() { local -r askWithTimeout_noAnswerFn=$3 local -r askWithTimeout_outVarName=$4 local -r askWithTimeout_readArgs=$5 - shift 5 || die "could not shift by 5" + shift 5 || traceAndDie "could not shift by 5" exitIfArgIsNotFunction "$askWithTimeout_noAnswerFn" 3 # shellcheck disable=SC2059 # the question itself can have %s thus we use it in the format string diff --git a/lib/tegonal-scripts/src/utility/checks.sh b/lib/tegonal-scripts/src/utility/checks.sh index 5cf68d3..6f6cdc0 100644 --- a/lib/tegonal-scripts/src/utility/checks.sh +++ b/lib/tegonal-scripts/src/utility/checks.sh @@ -7,7 +7,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # Functions to check declarations @@ -51,7 +51,7 @@ # # # shellcheck disable=SC2317 # is passed by name to exitIfArgIsNotArrayWithTuples # function describePair() { -# echo >&2 "array contains 2-tuples with names where the first value is the first-, and the second the lastname" +# echo >&2 "array contains 2-tuples with names where the first value is the first-, and the second the last name" # } # # check array with 2-tuples # exitIfArgIsNotArrayWithTuples arr 2 "names" 1 describePair @@ -70,6 +70,10 @@ # # meant to be used in a file which is sourced where a contract exists between the file which `source`s and the sourced file # exitIfVarsNotAlreadySetBySource myVar1 var2 var3 # +# declare myVar4 +# exitIfVariablesNotDeclared myVar4 myVar5 # would exit because myVar5 is not set +# echo "myVar4 $myVar4" +# ################################### set -euo pipefail shopt -s inherit_errexit @@ -92,7 +96,7 @@ function checkArgIsArray() { fi local -rn checkArgIsArray_arr=$1 local -r argNumberOrName=$2 - shift 2 || die "could not shift by 2" + shift 2 || traceAndDie "could not shift by 2" reg='^declare -a.*' local arrayDefinition @@ -117,9 +121,9 @@ function exitIfArgIsNotArrayOrIsEmpty() { exitIfArgIsNotArray "$@" local -rn exitIfArgIsNotArrayOrIsEmpty_arr=$1 local -r argNumberOrName=$2 - shift 2 || die "could not shift by 2" + shift 2 || traceAndDie "could not shift by 2" if [[ ${#exitIfArgIsNotArrayOrIsEmpty_arr[@]} -lt 1 ]]; then - die "the passed argument \033[0;36m%s\033[0m is an empty array" "${!checkArgIsArray_arr}" + traceAndDie "the passed argument \033[0;36m%s\033[0m is an empty array" "${!checkArgIsArray_arr}" fi } @@ -140,7 +144,7 @@ function checkArgIsArrayWithTuples() { local -r tupleRepresents=$3 local -r argNumberOrName=$4 local -r describeTupleFn=$5 - shift 5 || die "could not shift by 5" + shift 5 || traceAndDie "could not shift by 5" local -r arrLength=${#checkArgIsArrayWithTuples_paramArr[@]} @@ -152,7 +156,7 @@ function checkArgIsArrayWithTuples() { fi local arrayDefinition - arrayDefinition=$(recursiveDeclareP checkArgIsArrayWithTuples_paramArr) || die "could not get array definition of %s" "${!checkArgIsArrayWithTuples_paramArr}" + arrayDefinition=$(recursiveDeclareP checkArgIsArrayWithTuples_paramArr) || traceAndDie "could not get array definition of %s" "${!checkArgIsArrayWithTuples_paramArr}" reg='declare -a.*' if ! [[ "$arrayDefinition" =~ $reg ]]; then logError "the passed array \033[0;36m%s\033[0m is broken" "${!checkArgIsArrayWithTuples_paramArr}" @@ -254,7 +258,7 @@ function exitIfArgIsNotVersion() { function checkArgIsVersion() { local versionRegex - source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || die "could not source common-constants.source.sh" + source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh" local value argNumberOrName # shellcheck disable=SC2034 # is passed by name to parseFnArgs @@ -291,7 +295,18 @@ function exitIfCommandDoesNotExist() { function exitIfVarsNotAlreadySetBySource() { for varName in "$@"; do if ! [[ -v "$varName" ]] || [[ -z ${!varName} ]]; then - die "looks like \$%s was not defined by %s where this file (%s) was sourced" "$varName" "${BASH_SOURCE[2]:-${BASH_SOURCE[1]}}" "${BASH_SOURCE[0]}" + traceAndDie "looks like \$%s was not defined by %s where this file (%s) was sourced" "$varName" "${BASH_SOURCE[2]:-${BASH_SOURCE[1]}}" "${BASH_SOURCE[0]}" + fi + done +} + +function exitIfVariablesNotDeclared() { + shift 1 || traceAndDie "could not shift by 1" + for variableName in "$@"; do + if ! declare -p "$variableName" 2>/dev/null | grep -q 'declare --'; then + logError "you need to \`declare\` (\`local\`) the variable \033[0;36m%s\033[0m otherwise we write to the global scope (you can also \`declare\` it in the global scope)" "$variableName" + printStackTrace + exit 1 fi done } diff --git a/lib/tegonal-scripts/src/utility/git-utils.sh b/lib/tegonal-scripts/src/utility/git-utils.sh index fc27ca9..17f68a3 100644 --- a/lib/tegonal-scripts/src/utility/git-utils.sh +++ b/lib/tegonal-scripts/src/utility/git-utils.sh @@ -3,9 +3,9 @@ # __ __ # / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/scripts # / __/ -_) _ `/ _ \/ _ \/ _ `/ / It is licensed under Apache License 2.0 -# \__/\__/\_, /\___/_//_/\_,_/_/ Please remotert bugs and contribute back your improvements +# \__/\__/\_, /\___/_//_/\_,_/_/ Please report bugs and contribute back your improvements # /___/ -# Version: v3.2.0 +# Version: v3.5.0 # ####### Description ############# # @@ -60,6 +60,8 @@ # echo "latest tag on origin: $latestTag" # latestTag=$(latestRemoteTag upstream) # echo "latest tag on upstream: $latestTag" +# latestTag=$(latestRemoteTag origin "^v1\.[0-9]+\.[0-9]+$") +# echo "latest tag in the major 1.x.x series on origin without release candidates: $latestTag" # ################################### set -euo pipefail @@ -129,7 +131,7 @@ function hasRemoteTag() { fi local -r tag=$1 local -r remote=${2:-"origin"} - shift 1 || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" local output output=$(git ls-remote -t "$remote") || die "the following command failed (see above): git ls-remote -t \"$remote\"" grep "$tag" >/dev/null <<<"$output" @@ -139,7 +141,7 @@ function remoteTagsSorted() { local remote="origin" if (($# > 0)); then remote=$1 - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" fi git ls-remote --refs --tags "$remote" | cut --delimiter='/' --fields=3 | @@ -147,13 +149,18 @@ function remoteTagsSorted() { } function latestRemoteTag() { - if (($# > 1)); then - traceAndDie "you can optionally pass the name of the remote (defaults to origin) to latestRemoteTag but not more, given: %s" "$#" + if (($# > 2)); then + logError "Maximum 2 arguments can be passed to latestRemoteTag, given \033[0;36m%s\033[0m\n" "$#" + echo >&2 '1: remote (optional) the name of the remote, defaults to origin' + echo >&2 '2: tagFilter (optional) a regex pattern (as supported by grep -E) which allows to filter available tags before determining the latest, defaults to .* (i.e. include all)' + printStackTrace + exit 9 fi local -r remote=${1:-"origin"} + local -r tagFilter=${2:-".*"} local tag #shellcheck disable=SC2310 # we are aware of that || will disable set -e for remoteTagsSorted - tag=$(remoteTagsSorted "$remote" | tail -n 1) || die "could not get remote tags sorted, see above" + tag=$(remoteTagsSorted "$remote" | grep -E "$tagFilter" | tail -n 1) || die "could not get remote tags sorted for remote %s, see above" "$remote" if [[ -z $tag ]]; then die "looks like remote \033[0;36m%s\033[0m does not have a tag yet." "$remote" fi diff --git a/lib/tegonal-scripts/src/utility/gpg-utils.sh b/lib/tegonal-scripts/src/utility/gpg-utils.sh index aa434e7..56b355d 100644 --- a/lib/tegonal-scripts/src/utility/gpg-utils.sh +++ b/lib/tegonal-scripts/src/utility/gpg-utils.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # utility functions for dealing with gpg diff --git a/lib/tegonal-scripts/src/utility/io.sh b/lib/tegonal-scripts/src/utility/io.sh index bfc2452..612c887 100644 --- a/lib/tegonal-scripts/src/utility/io.sh +++ b/lib/tegonal-scripts/src/utility/io.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # utility function dealing with Input/Ouput @@ -54,14 +54,14 @@ function withCustomOutputInput() { local outputNr=$1 local inputNr=$2 local fun=$3 - shift 3 || die "could not shift by 3" + shift 3 || traceAndDie "could not shift by 3" exitIfArgIsNotFunction "$fun" 3 local tmpFile tmpFile=$(mktemp /tmp/tegonal-scripts-io.XXXXXXXXX) - eval "exec ${outputNr}>\"$tmpFile\"" || die "could not create output file descriptor %s" "$outputNr" - eval "exec ${inputNr}<\"$tmpFile\"" || die "could not create input file descriptor %s" "$inputNr" + eval "exec ${outputNr}>\"$tmpFile\"" || traceAndDie "could not create output file descriptor %s" "$outputNr" + eval "exec ${inputNr}<\"$tmpFile\"" || traceAndDie "could not create input file descriptor %s" "$inputNr" # don't fail if we cannot delete the tmp file, if this should happened, then the system should clean-up the file when the process ends rm "$tmpFile" || true @@ -73,7 +73,7 @@ function withCustomOutputInput() { function deleteDirChmod777() { local -r dir=$1 - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" # e.g files in .git will be write-protected and we don't want sudo for this command # yet, if it fails, then we ignore the problem and still try to delete the folder chmod -R 777 "$dir" || true diff --git a/lib/tegonal-scripts/src/utility/log.sh b/lib/tegonal-scripts/src/utility/log.sh index 15eacc1..e70124d 100644 --- a/lib/tegonal-scripts/src/utility/log.sh +++ b/lib/tegonal-scripts/src/utility/log.sh @@ -7,7 +7,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # Utility functions wrapping printf and prefixing the message with a coloured INFO, WARNING or ERROR. @@ -88,45 +88,45 @@ unset CDPATH function logInfo() { local msg=$1 - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" logInfoWithoutNewline "$msg\n" "$@" } function logInfoWithoutNewline() { local msg=$1 - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" printf "\033[0;34mINFO\033[0m: $msg" "$@" } function logWarning() { local msg=$1 - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" logWarningWithoutNewline "$msg\n" "$@" } function logWarningWithoutNewline() { local msg=$1 - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" printf "\033[0;93mWARNING\033[0m: $msg" "$@" } function logError() { local msg=$1 - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" logErrorWithoutNewline "$msg\n" "$@" } function logErrorWithoutNewline() { local msg=$1 - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" printf >&2 "\033[0;31mERROR\033[0m: $msg" "$@" } function logSuccess() { local msg=$1 - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" logSuccessWithoutNewline "$msg\n" "$@" } function logSuccessWithoutNewline() { local msg=$1 - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" printf "\033[0;32mSUCCESS\033[0m: $msg" "$@" } diff --git a/lib/tegonal-scripts/src/utility/parse-args.sh b/lib/tegonal-scripts/src/utility/parse-args.sh index 83f6208..0cbf6f4 100644 --- a/lib/tegonal-scripts/src/utility/parse-args.sh +++ b/lib/tegonal-scripts/src/utility/parse-args.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # Intended to parse command line arguments. Provides a simple way to parse named arguments including a documentation @@ -74,6 +74,7 @@ if ! [[ -v dir_of_tegonal_scripts ]]; then source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts" fi sourceOnce "$dir_of_tegonal_scripts/utility/array-utils.sh" +sourceOnce "$dir_of_tegonal_scripts/utility/ask.sh" sourceOnce "$dir_of_tegonal_scripts/utility/checks.sh" sourceOnce "$dir_of_tegonal_scripts/utility/parse-utils.sh" @@ -127,14 +128,19 @@ function parseArgumentsInternal { local -rn parseArguments_paramArr=$2 local -r parseArguments_examples=$3 local -r parseArguments_version=$4 - shift 4 || die "could not shift by 4" + shift 4 || traceAndDie "could not shift by 4" if ! [[ "$parseArguments_unknownBehaviour" =~ ^(ignore|error)$ ]]; then - die "unknownBehaviour needs to be one of 'error' or 'ignore' got \033[0;36m%s\033[0m" "$parseArguments_unknownBehaviour" + traceAndDie "unknownBehaviour needs to be one of 'error' or 'ignore' got \033[0;36m%s\033[0m" "$parseArguments_unknownBehaviour" fi parse_args_exitIfParameterDefinitionIsNotTriple parseArguments_paramArr + # shellcheck disable=SC2034 # passed by name to exitIfVariablesNotDeclared + local -a parseArguments_variableNames + arrTakeEveryX parseArguments_paramArr parseArguments_variableNames 3 0 + exitIfVariablesNotDeclared "${parseArguments_variableNames[@]}" + local -ri parseArguments_arrLength="${#parseArguments_paramArr[@]}" local -i parseArguments_numOfArgumentsParsed=0 @@ -173,24 +179,25 @@ function parseArgumentsInternal { exit 9 fi # that's where the black magic happens, we are assigning to global (not local to this function) variables here - printf -v "$parseArguments_paramName" "%s" "$2" || die "could not assign value to $parseArguments_paramName" + printf -v "$parseArguments_paramName" "%s" "$2" || traceAndDie "could not assign value to $parseArguments_paramName" parseArguments_expectedName=1 ((++parseArguments_numOfArgumentsParsed)) - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" fi done if [[ $parseArguments_unknownBehaviour = 'error' ]] && ((parseArguments_expectedName == 0)); then - parse_args_printHelp >&2 parseArguments_paramArr "$parseArguments_examples" "$parseArguments_version" if [[ $parseArguments_argName =~ ^- ]] && (($# > 1)); then logError "unknown argument \033[1;36m%s\033[0m (and value %s)" "$parseArguments_argName" "$2" else logError "unknown argument \033[1;36m%s\033[0m" "$parseArguments_argName" fi - echo >&2 "consult the output of --help shown further above for valid names" + if askYesOrNo "Shall I print the help for you?"; then + parse_args_printHelp >&2 parseArguments_paramArr "$parseArguments_examples" "$parseArguments_version" + fi exit 9 fi - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" done } @@ -255,7 +262,7 @@ function exitIfNotAllArgumentsSet { local -rn exitIfNotAllArgumentsSet_paramArr=$1 local -r exitIfNotAllArgumentsSet_examples=$2 local -r exitIfNotAllArgumentsSet_version=$3 - shift 3 || die "could not shift by 3" + shift 3 || traceAndDie "could not shift by 3" # it is handy to see the stacktrace if it is not a direct call from command line # where we assume that the script as such has a "main" function, this one calls one function from this file and diff --git a/lib/tegonal-scripts/src/utility/parse-commands.sh b/lib/tegonal-scripts/src/utility/parse-commands.sh index b9dde5a..1f2fffb 100644 --- a/lib/tegonal-scripts/src/utility/parse-commands.sh +++ b/lib/tegonal-scripts/src/utility/parse-commands.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # Intended to parse command line arguments of a script which uses commands and delegates accordingly. @@ -117,7 +117,7 @@ function parseCommands { local -r version=$2 local -r sourceFn=$3 local -r fnPrefix=$4 - shift 4 || die "could not shift by 4" + shift 4 || traceAndDie "could not shift by 4" if (($# < 1 )); then logError "no command passed to %s, following the output of --help\n" "$(basename "${BASH_SOURCE[1]}")" @@ -129,7 +129,7 @@ function parseCommands { exitIfArgIsNotFunction "$sourceFn" 3 local -r command=$1 - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" local -a commandNames=() arrTakeEveryX parseCommands_paramArr commandNames 2 0 local tmpRegex regex @@ -138,7 +138,7 @@ function parseCommands { local -r tmpRegex regex if [[ "$command" =~ $regex ]]; then - "$sourceFn" "$command" || die "could not source necessary files to bring in function for command %s" "$command" + "$sourceFn" "$command" || traceAndDie "could not source necessary files to bring in function for command %s" "$command" "$fnPrefix${command/-/_}" "$@" elif [[ "$command" == "--help" ]]; then parse_commands_printHelp parseCommands_paramArr "$version" diff --git a/lib/tegonal-scripts/src/utility/parse-fn-args.sh b/lib/tegonal-scripts/src/utility/parse-fn-args.sh index 925e174..8e8a920 100644 --- a/lib/tegonal-scripts/src/utility/parse-fn-args.sh +++ b/lib/tegonal-scripts/src/utility/parse-fn-args.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # Intended to parse positional function parameters including assignment and check if there are enough arguments @@ -74,7 +74,7 @@ function parseFnArgs() { # using unconventional naming in order to avoid name clashes with the variables we will initialise further below local -rn parseFnArgs_paramArr1=$1 - shift 1 || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" exitIfArgIsNotArray parseFnArgs_paramArr1 1 @@ -127,17 +127,19 @@ function parseFnArgs() { exit 9 fi + exitIfVariablesNotDeclared "${parseFnArgs_paramArr1[@]}" + for ((parseFnArgs_i = 0; parseFnArgs_i < parseFnArgs_minExpected; ++parseFnArgs_i)); do local parseFnArgs_name=${parseFnArgs_paramArr1[parseFnArgs_i]} # assign arguments to specified variables - printf -v "$parseFnArgs_name" "%s" "$1" || die "could not assign value to $parseFnArgs_name" + printf -v "$parseFnArgs_name" "%s" "$1" || traceAndDie "could not assign value to $parseFnArgs_name" local -r "$parseFnArgs_name" - shift || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" done # assign rest to varargs if used if [[ $parseFnArgs_withVarArgs == true ]]; then # shellcheck disable=SC2034 # varargs is defined in outer scope and will be used there, thus ok - varargs=("$@") || die "could not assign the rest of arguments to varargs" + varargs=("$@") || traceAndDie "could not assign the rest of arguments to varargs" fi } diff --git a/lib/tegonal-scripts/src/utility/parse-utils.sh b/lib/tegonal-scripts/src/utility/parse-utils.sh index bb345d3..a04b699 100644 --- a/lib/tegonal-scripts/src/utility/parse-utils.sh +++ b/lib/tegonal-scripts/src/utility/parse-utils.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # Intended to parse command line arguments. Provides a simple way to parse named arguments including a documentation @@ -31,7 +31,7 @@ # function myParseFunction() { # while (($# > 0)); do # if [[ $1 == "--version" ]]; then -# shift || die "could not shift by 1" +# shift 1 || traceAndDie "could not shift by 1" # printVersion "$MY_LIBRARY_VERSION" # fi # #... diff --git a/lib/tegonal-scripts/src/utility/recursive-declare-p.sh b/lib/tegonal-scripts/src/utility/recursive-declare-p.sh index fb34116..714bf64 100644 --- a/lib/tegonal-scripts/src/utility/recursive-declare-p.sh +++ b/lib/tegonal-scripts/src/utility/recursive-declare-p.sh @@ -7,7 +7,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # Utility function which returns the `declare` statement of a variable with given name where it recursively calls diff --git a/lib/tegonal-scripts/src/utility/replace-help-snippet.sh b/lib/tegonal-scripts/src/utility/replace-help-snippet.sh index 8662658..ab06c21 100644 --- a/lib/tegonal-scripts/src/utility/replace-help-snippet.sh +++ b/lib/tegonal-scripts/src/utility/replace-help-snippet.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # Helper script do capture the `--help` output of a script and replace a snippet in HTML based scripts (e.g. in a Markdown script). diff --git a/lib/tegonal-scripts/src/utility/replace-snippet.sh b/lib/tegonal-scripts/src/utility/replace-snippet.sh index 8264408..dbe3603 100644 --- a/lib/tegonal-scripts/src/utility/replace-snippet.sh +++ b/lib/tegonal-scripts/src/utility/replace-snippet.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # Helper script do replace a snippet in HTML based files (e.g. in a Markdown file). diff --git a/lib/tegonal-scripts/src/utility/source-once.sh b/lib/tegonal-scripts/src/utility/source-once.sh index 9e7a229..fd10b70 100644 --- a/lib/tegonal-scripts/src/utility/source-once.sh +++ b/lib/tegonal-scripts/src/utility/source-once.sh @@ -7,7 +7,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 ####### Description ############# # # Utility functions wrapping printf and prefixing the message with a coloured INFO, WARNING or ERROR. @@ -71,7 +71,7 @@ function sourceOnce() { sourceOnce_exitIfNotAtLeastOneArg "$@" local -r sourceOnce_file="$1" - shift 1 || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" local sourceOnce_guard sourceOnce_guard=$(determineSourceOnceGuard "$sourceOnce_file") @@ -108,7 +108,7 @@ function sourceAlways() { sourceOnce_exitIfNotAtLeastOneArg "$@" local -r sourceAlways_file="$1" - shift 1 || die "could not shift by 1" + shift 1 || traceAndDie "could not shift by 1" local sourceAlways_guard sourceAlways_guard=$(determineSourceOnceGuard "$sourceAlways_file") diff --git a/lib/tegonal-scripts/src/utility/update-bash-docu.sh b/lib/tegonal-scripts/src/utility/update-bash-docu.sh index 73f9863..6c6474b 100644 --- a/lib/tegonal-scripts/src/utility/update-bash-docu.sh +++ b/lib/tegonal-scripts/src/utility/update-bash-docu.sh @@ -6,7 +6,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 # /___/ Please report bugs and contribute back your improvements # -# Version: v3.2.0 +# Version: v3.5.0 # ####### Description ############# #