From 4f33d5de0ba6911081c1b7768739946697ab6ba8 Mon Sep 17 00:00:00 2001
From: Jens Steidl <Jens.Steidl@slub-dresden.de>
Date: Mon, 25 Sep 2023 16:31:46 +0200
Subject: [PATCH] - refactor: added lists & new checks for some parameters

---
 src/usr/local/bin/validate_workflow.sh | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/usr/local/bin/validate_workflow.sh b/src/usr/local/bin/validate_workflow.sh
index c573fa4..cb14bf5 100755
--- a/src/usr/local/bin/validate_workflow.sh
+++ b/src/usr/local/bin/validate_workflow.sh
@@ -63,6 +63,12 @@
 # expected programs:
 # file, ...
 
+# PARAMETER VALUES LISTS
+DELIMITER=","
+MODE_LIST="auto,mediathek,fotothek,save,ddz,digas"
+STAGE_LIST="current,upcoming,any"
+FILES_MODE_LIST="sort,delete,nothing"
+
 # DEFAULTS
 WITH_DAEMON=0
 WITH_DEBUG=0
@@ -264,17 +270,12 @@ get_cli_args() {
                 ;;
         esac
     done
-    if [[ "${FILES_MODE}" != "sort" ]] && [[ "${FILES_MODE}" != "delete" ]] && [[ "${FILES_MODE}" != "nothing" ]]; then
-        error "param --files-mode must be 'sort', 'delete' or 'nothing'!"
+    if ! [[ "${FILES_MODE_LIST}" =~ (${DELIMITER}|^)${FILES_MODE}(${DELIMITER}|$) ]]; then
+        error "param --files-mode value must be one of the following '${FILES_MODE_LIST}'!"
         exit 1
     fi
-    if [[ "${MODE}" != "auto" ]] \
-        && [[ "${MODE}" != "mediathek" ]] \
-        && [[ "${MODE}" != "fotothek" ]] \
-        && [[ "${MODE}" != "save" ]] \
-        && [[ "${MODE}" != "ddz" ]] \
-        && [[ "${MODE}" != "digas" ]]; then
-        error "param --mode must be 'auto', 'mediathek', 'fotothek', 'save', 'ddz' or 'digas'!"
+    if ! [[ "${MODE_LIST}" =~ (${DELIMITER}|^)${MODE}(${DELIMITER}|$) ]]; then
+        error "param --mode value must be one of the following '${MODE_LIST}'!"
         exit 1
     fi
     if [[ "${WITH_PIPE}" -eq 1 ]]; then
@@ -294,8 +295,8 @@ get_cli_args() {
             error "param --daemon does only work with param --mode='delete' or --mode='nothing'!"
             exit 1
         fi
-        if [[ "${STAGE}" != "current" ]] && [[ "${STAGE}" != "upcoming" ]] && [[ "${STAGE}" != "any" ]]; then
-            error "--param stage must be 'any', 'current' or 'upcoming'!"
+        if ! [[ "${STAGE_LIST}" =~ (${DELIMITER}|^)${STAGE}(${DELIMITER}|$) ]]; then
+            error "param --stage value must be one of the following '${STAGE_LIST}'!"
             exit 1
         fi
         if [[ ! -d "${WATCH_FOLDER}" ]]; then
-- 
GitLab