From 4c161aba49cb8e9730e4318140d972221f9833a1 Mon Sep 17 00:00:00 2001 From: yage Date: Tue, 22 Aug 2023 14:20:03 -0600 Subject: [PATCH] v3.4.0 ===================================================================== --- Changes ------------------------------ - Allow the group variable `REQUIRED_ENVIRONMENT_REGEX` to enforce that only some environments can run within the group --- run | 10 ++++++++++ zsh/lib/scwrypts/environment-files.module.zsh | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/run b/run index e26a851..26b61b5 100755 --- a/run +++ b/run @@ -208,6 +208,12 @@ __RUN() { ########################################## local ENV_REQUIRED=$(__CHECK_ENV_REQUIRED && echo 1 || echo 0) + local REQUIRED_ENVIRONMENT_REGEX=$(eval echo '$SCWRYPTS_REQUIRED_ENVIRONMENT_REGEX__'$SCWRYPT_GROUP) + + [ $REQUIRED_ENVIRONMENT_REGEX ] && { + [[ $ENV_NAME =~ $REQUIRED_ENVIRONMENT_REGEX ]] \ + || FAIL 5 "group '$SCWRYPT_GROUP' requires current environment to match '$REQUIRED_ENVIRONMENT_REGEX' (currently $ENV_NAME)" + } [[ $ENV_REQUIRED -eq 1 ]] && { [ ! $ENV_NAME ] && ENV_NAME=$(SCWRYPTS__SELECT_ENV) @@ -225,6 +231,10 @@ __RUN() { export ENV_NAME } + [ $REQUIRED_ENVIRONMENT_REGEX ] && { + [[ $ENV_NAME =~ $REQUIRED_ENVIRONMENT_REGEX ]] \ + || FAIL 5 "group '$SCWRYPT_GROUP' requires current environment to match '$REQUIRED_ENVIRONMENT_REGEX' (currently $ENV_NAME)" + } ########################################## diff --git a/zsh/lib/scwrypts/environment-files.module.zsh b/zsh/lib/scwrypts/environment-files.module.zsh index 33f50e0..060bfe8 100644 --- a/zsh/lib/scwrypts/environment-files.module.zsh +++ b/zsh/lib/scwrypts/environment-files.module.zsh @@ -64,7 +64,11 @@ SCWRYPTS__GET_ENV_NAMES() { ERROR 'environment initialization error' return 1 } - ls "$SCWRYPTS_ENV_PATH/scwrypts" | sort -r + [ $REQUIRED_ENVIRONMENT_REGEX ] && { + ls "$SCWRYPTS_ENV_PATH/scwrypts" | grep "$REQUIRED_ENVIRONMENT_REGEX" | sort -r + } || { + ls "$SCWRYPTS_ENV_PATH/scwrypts" | sort -r + } } SCWRYPTS__INIT_ENVIRONMENTS() {