Add exclude powers option. Add subshell to isolate variables.
This commit is contained in:
parent
fcb77c8f3e
commit
7a53c0acb9
@ -3,8 +3,8 @@
|
||||
# Program name
|
||||
PROGRAM_NAME="OctoPower"
|
||||
PROGRAM_CODE="octopower"
|
||||
PROGRAM_VERSION="1.0.1"
|
||||
PROGRAM_V="1.0"
|
||||
PROGRAM_VERSION="2.0.0"
|
||||
PROGRAM_V="2.0"
|
||||
PROGRAM_URL="https://git.vdm.dev/octoleo/${PROGRAM_CODE}"
|
||||
|
||||
# Do some prep work
|
||||
@ -29,6 +29,8 @@ command -v sed >/dev/null 2>&1 || {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Subshell to isolate variables
|
||||
(
|
||||
# main function ˘Ô≈ôﺣ
|
||||
function main() {
|
||||
# check if we have project overrides for the environment variables
|
||||
@ -219,6 +221,14 @@ function setPowers() {
|
||||
local has_powers=false
|
||||
# load all the repositories
|
||||
loadSuperpowerRepositories || return 13
|
||||
# Check if the .exclude-powers[] field exists and is not empty
|
||||
if [ "$(echo "${VDM_CONFIG_DATA}" | jq '.exclude_powers | length')" -gt 0 ]; then
|
||||
# Iterate over the exclude-powers array
|
||||
for exclude_power in $(echo "${VDM_CONFIG_DATA}" | jq -r '.exclude_powers[]'); do
|
||||
# Load the exclude power
|
||||
loadExcludePower "${exclude_power}"
|
||||
done
|
||||
fi
|
||||
# search for the powers
|
||||
for power in $(echo "${VDM_CONFIG_DATA}" | jq -r '.powers[]'); do
|
||||
# load the power
|
||||
@ -230,16 +240,54 @@ function setPowers() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# load the exclude power
|
||||
function loadExcludePower() {
|
||||
local guid="$1"
|
||||
if [[ $guid == "//"* ]]; then
|
||||
return 0 # skip comments ;)
|
||||
elif [ ${#guid} -ge 30 ] && validateGuid "${guid}"; then
|
||||
setExcludePower "$guid" || return 19
|
||||
return 0
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# set the exclude power found
|
||||
function setExcludePower() {
|
||||
local guid="$1"
|
||||
|
||||
# Remove the power from VDM_POWERS if it exists
|
||||
if existingPower "$guid"; then
|
||||
VDM_POWERS=$(jq --arg guid "$guid" '
|
||||
map(select(. != $guid))
|
||||
' <<< "$VDM_POWERS")
|
||||
fi
|
||||
|
||||
# check if we have already loaded this power
|
||||
existingExcludePower "${guid}" && return 0
|
||||
|
||||
# Add the guid to VDM_EXCLUDE_POWERS
|
||||
VDM_EXCLUDE_POWERS=$(jq --arg guid "$guid" '
|
||||
. + [ $guid ]
|
||||
' <<< "$VDM_EXCLUDE_POWERS")
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# load the power
|
||||
function loadPower() {
|
||||
local guid="$1"
|
||||
if [[ $guid == "//"* ]]; then
|
||||
return 0 # skip comments ;)
|
||||
elif [ ${#guid} -ge 30 ] && validateGuid "${guid}"; then
|
||||
if existingExcludePower "$guid"; then
|
||||
return 0 # skip excluded ;)
|
||||
else
|
||||
setPower "$guid" || return 19
|
||||
loadChildrenPowers "$guid" || return 19
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 19
|
||||
}
|
||||
|
||||
@ -362,6 +410,23 @@ function loadChildrenPowers() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# Check if a given power already exists in VDM_EXCLUDE_POWERS
|
||||
function existingExcludePower() {
|
||||
local guid="$1"
|
||||
local exists
|
||||
|
||||
# Check if the power is already in VDM_EXCLUDE_POWERS
|
||||
exists=$(jq --arg guid "$guid" '
|
||||
map(select(. == $guid)) | length > 0
|
||||
' <<< "$VDM_EXCLUDE_POWERS")
|
||||
|
||||
if [ "$exists" = "true" ]; then
|
||||
return 0 # GUID exists
|
||||
else
|
||||
return 1 # GUID does not exist
|
||||
fi
|
||||
}
|
||||
|
||||
# Check if a given power already exists in VDM_POWERS
|
||||
function existingPower() {
|
||||
local guid="$1"
|
||||
@ -1857,8 +1922,10 @@ if [ -f "$VDM_ENV_FILE_PATH" ]; then
|
||||
fi
|
||||
|
||||
# Initialize the global JSON array if not already initialized
|
||||
VDM_SUPERPOWERS=${VDM_SUPERPOWERS:-"[]"}
|
||||
VDM_POWERS=${VDM_POWERS:-"[]"}
|
||||
: "${VDM_SUPERPOWERS:="[]"}"
|
||||
: "${VDM_POWERS:="[]"}"
|
||||
: "${VDM_EXCLUDE_POWERS:="[]"}"
|
||||
|
||||
# Create a global temporary file to store the dataset
|
||||
VDM_SUPERPOWERS_FILE=$(mktemp)
|
||||
# Initialize the global variable as an empty array or use the environment value if provided
|
||||
@ -1907,6 +1974,7 @@ fi
|
||||
}
|
||||
|
||||
# run Main ┬┴┬┴┤(・_├┬┴┬┴
|
||||
main
|
||||
main "$@"
|
||||
)
|
||||
|
||||
exit 0
|
||||
|
Loading…
Reference in New Issue
Block a user