From 2ed5961601a1231606d2ac7f3ed4a36ee481fbde Mon Sep 17 00:00:00 2001 From: Robert Stoll Date: Tue, 16 Apr 2024 22:28:32 +0200 Subject: [PATCH] introduce checkArgIsVersion --- README.md | 11 +++++---- src/utility/checks.doc.sh | 11 +++++---- src/utility/checks.sh | 48 +++++++++++++++++++++++++++++++-------- 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b8df6354..73c4c49e 100644 --- a/README.md +++ b/README.md @@ -1317,11 +1317,13 @@ function foo() { local -rn arr=$1 local -r fn=$2 local -r bool=$3 + local -r version=$4 # resolves arr recursively via recursiveDeclareP and check that is a non-associative array - checkArgIsArray arr 1 # same as exitIfArgIsNotArray if set -e has an effect on this line - checkArgIsFunction "$fn" 2 # same as exitIfArgIsNotFunction if set -e has an effect on this line - checkArgIsBoolean "$bool" 3 # same as exitIfArgIsNotBoolean if set -e has an effect on this line + checkArgIsArray arr 1 # same as exitIfArgIsNotArray if set -e has an effect on this line + checkArgIsFunction "$fn" 2 # same as exitIfArgIsNotFunction if set -e has an effect on this line + checkArgIsBoolean "$bool" 3 # same as exitIfArgIsNotBoolean if set -e has an effect on this line + checkArgIsVersion "$version" 4 # same as exitIfArgIsNotVersion if set -e has an effect on this line # shellcheck disable=SC2317 # is passed by name to checkArgIsArrayWithTuples function describeTriple() { @@ -1333,7 +1335,8 @@ function foo() { exitIfArgIsNotArray arr 1 exitIfArgIsNotArrayOrIsEmpty arr 1 exitIfArgIsNotFunction "$fn" 2 - exitIfArgIsNotBoolean "$bool" 2 + exitIfArgIsNotBoolean "$bool" 3 + exitIfArgIsNotVersion "$version" 4 # shellcheck disable=SC2317 # is passed by name to exitIfArgIsNotArrayWithTuples function describePair() { diff --git a/src/utility/checks.doc.sh b/src/utility/checks.doc.sh index 606af8ef..041dd38a 100644 --- a/src/utility/checks.doc.sh +++ b/src/utility/checks.doc.sh @@ -12,11 +12,13 @@ function foo() { local -rn arr=$1 local -r fn=$2 local -r bool=$3 + local -r version=$4 # resolves arr recursively via recursiveDeclareP and check that is a non-associative array - checkArgIsArray arr 1 # same as exitIfArgIsNotArray if set -e has an effect on this line - checkArgIsFunction "$fn" 2 # same as exitIfArgIsNotFunction if set -e has an effect on this line - checkArgIsBoolean "$bool" 3 # same as exitIfArgIsNotBoolean if set -e has an effect on this line + checkArgIsArray arr 1 # same as exitIfArgIsNotArray if set -e has an effect on this line + checkArgIsFunction "$fn" 2 # same as exitIfArgIsNotFunction if set -e has an effect on this line + checkArgIsBoolean "$bool" 3 # same as exitIfArgIsNotBoolean if set -e has an effect on this line + checkArgIsVersion "$version" 4 # same as exitIfArgIsNotVersion if set -e has an effect on this line # shellcheck disable=SC2317 # is passed by name to checkArgIsArrayWithTuples function describeTriple() { @@ -28,7 +30,8 @@ function foo() { exitIfArgIsNotArray arr 1 exitIfArgIsNotArrayOrIsEmpty arr 1 exitIfArgIsNotFunction "$fn" 2 - exitIfArgIsNotBoolean "$bool" 2 + exitIfArgIsNotBoolean "$bool" 3 + exitIfArgIsNotVersion "$version" 4 # shellcheck disable=SC2317 # is passed by name to exitIfArgIsNotArrayWithTuples function describePair() { diff --git a/src/utility/checks.sh b/src/utility/checks.sh index 688ace1a..de0ea2c7 100644 --- a/src/utility/checks.sh +++ b/src/utility/checks.sh @@ -28,11 +28,13 @@ # local -rn arr=$1 # local -r fn=$2 # local -r bool=$3 +# local -r version=$4 # # # resolves arr recursively via recursiveDeclareP and check that is a non-associative array -# checkArgIsArray arr 1 # same as exitIfArgIsNotArray if set -e has an effect on this line -# checkArgIsFunction "$fn" 2 # same as exitIfArgIsNotFunction if set -e has an effect on this line -# checkArgIsBoolean "$bool" 3 # same as exitIfArgIsNotBoolean if set -e has an effect on this line +# checkArgIsArray arr 1 # same as exitIfArgIsNotArray if set -e has an effect on this line +# checkArgIsFunction "$fn" 2 # same as exitIfArgIsNotFunction if set -e has an effect on this line +# checkArgIsBoolean "$bool" 3 # same as exitIfArgIsNotBoolean if set -e has an effect on this line +# checkArgIsVersion "$version" 4 # same as exitIfArgIsNotVersion if set -e has an effect on this line # # # shellcheck disable=SC2317 # is passed by name to checkArgIsArrayWithTuples # function describeTriple() { @@ -44,7 +46,8 @@ # exitIfArgIsNotArray arr 1 # exitIfArgIsNotArrayOrIsEmpty arr 1 # exitIfArgIsNotFunction "$fn" 2 -# exitIfArgIsNotBoolean "$bool" 2 +# exitIfArgIsNotBoolean "$bool" 3 +# exitIfArgIsNotVersion "$version" 4 # # # shellcheck disable=SC2317 # is passed by name to exitIfArgIsNotArrayWithTuples # function describePair() { @@ -112,12 +115,12 @@ function exitIfArgIsNotArray() { function exitIfArgIsNotArrayOrIsEmpty() { exitIfArgIsNotArray "$@" - local -rn exitIfArgIsNotArrayOrIsEmpty_arr=$1 - local -r argNumberOrName=$2 - shift 2 || die "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}" - fi + local -rn exitIfArgIsNotArrayOrIsEmpty_arr=$1 + local -r argNumberOrName=$2 + shift 2 || die "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}" + fi } function checkArgIsArrayWithTuples() { @@ -243,6 +246,31 @@ function exitIfArgIsNotBoolean() { # shellcheck disable=SC2310 # we are aware of that || will disable set -e for checkArgIsBoolean checkArgIsBoolean "$@" || exit $? } + +function exitIfArgIsNotVersion() { + # shellcheck disable=SC2310 # we are aware of that || will disable set -e for checkArgIsVersion + checkArgIsVersion "$@" || exit $? +} + +function checkArgIsVersion() { + local versionRegex + source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || die "could not source common-constants.source.sh" + + local value argNumberOrName + # shellcheck disable=SC2034 # is passed by name to parseFnArgs + local -ra params=(value argNumberOrName) + parseFnArgs params "$@" + + if ! [[ "$value" =~ $versionRegex ]]; then + local funcName=${FUNCNAME[1]} + if [[ $funcName == "exitIfArgIsNotVersion" ]]; then + funcName=${FUNCNAME[2]} + fi + traceAndReturnDying "the %s argument to %s needs to match vX.Y.Z(-RC...) was %s" \ + "$argNumberOrName" "$funcName" "$value" + fi +} + function checkCommandExists() { if ! (($# == 1 || $# == 2)); then traceAndDie "you need to pass the name of the command to check to checkCommandExists and optionally an additional hint (e.g. install via...)"