Skip to content

Commit

Permalink
Check pattern success
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbode committed Mar 26, 2024
1 parent 2c51382 commit 67fdabc
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions bin/utils.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env bash

if [ "${MISE_TRACE-}" = "1" ]; then
if [[ ${MISE_TRACE-} == 1 ]]; then
set -x
fi

Expand All @@ -9,14 +9,14 @@ echoerr() {
}

sops_bin() {
echo "${MISE_INSTALL_PATH}/bin/sops"
"${MISE_INSTALL_PATH}/bin/sops" "$@"
}

DELIMS="[,;:]"

sops_env() {
if [[ -z ${MISE_TOOL_OPTS__FILENAME-} ]]; then
echoerr "mise-sops: No filename provided."
echoerr "mise-sops: no filename provided"
return 1
fi

Expand All @@ -32,18 +32,35 @@ sops_env() {
NAMES="^export ([a-zA-Z0-9_]+)="
fi

FILES=0
LINES=0

while read -r filename; do
if [[ ${filename} != /* ]] && [[ -n ${MISE_PROJECT_ROOT-} ]]; then
filename="${MISE_PROJECT_ROOT-}/${filename}"
fi

if [[ ! -f ${filename} ]]; then
echoerr "mise-sops: Filename '${filename}' not found."
echoerr "mise-sops: filename not found: ${filename}"
continue
fi

((FILES++))

while read -r LINE; do
if [[ ${LINE} =~ ${NAMES} ]]; then
((LINES++))
printf '%s\n' "${LINE}"
fi
done < <("$(sops_bin)" -d "${filename}")
done < <(sops_bin -d "${filename}")
done <<< "${FILENAMES}"

if ((!FILES)); then
return 1
fi

if ((!LINES)); then
echoerr "mise-sops: no variables match name pattern: ${MISE_TOOL_OPTS__NAMES-}"
return 1
fi
}

0 comments on commit 67fdabc

Please sign in to comment.