Skip to content

Commit

Permalink
style: shfmt bin/list-legacy-filenames
Browse files Browse the repository at this point in the history
Fix #41
  • Loading branch information
virtualroot committed Sep 18, 2024
1 parent 1009a22 commit d65ef27
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions bin/parse-legacy-file
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,54 @@ THIS_PLUGIN="${ASDF_OPENTOFU_THIS_PLUGIN:-"$(basename "$(dirname "$(dirname "$0"
SUPPORTED_PLUGINS=(opentofu)

is_strict_equality_version_constraint() {
local -r version_constraint="$1"
grep --quiet -E '^=?[[:digit:]]+\.[[:digit:]]+.[[:digit:]]+' <<<"${version_constraint}"
local -r version_constraint="$1"
grep --quiet -E '^=?[[:digit:]]+\.[[:digit:]]+.[[:digit:]]+' <<<"${version_constraint}"
}

read_version_from_main_tofu() {
local -r version_file="$1"
local -r required_version_constraint="$(grep --no-filename \
--recursive \
--fixed-strings \
required_version \
"${version_file}" |
sed -E 's/[[:space:]]*required_version[[:space:]]*=//' |
tr -d '" ')"
local -r version_file="$1"
local -r required_version_constraint="$(grep --no-filename \
--recursive \
--fixed-strings \
required_version \
"${version_file}" |
sed -E 's/[[:space:]]*required_version[[:space:]]*=//' |
tr -d '" ')"

[[ -z ${required_version_constraint} ]] && return 0
[[ -z ${required_version_constraint} ]] && return 0

if is_strict_equality_version_constraint "${required_version_constraint}"; then
tr -d '=' <<<"${required_version_constraint}"
else
cat >&2 <<EOF
if is_strict_equality_version_constraint "${required_version_constraint}"; then
tr -d '=' <<<"${required_version_constraint}"
else
cat >&2 <<EOF
FATAL: Found legacy version file '${ASDF_OPENTOFU_VERSION_FILE:-main.tofu}' with unsupported required
version constraint expression: '${required_version_constraint}'. This
plugin only supports strict equality.
EOF
exit 1
fi
exit 1
fi
}

get_legacy_version() {
local -r version_file="$1"
local this_plugin_supported=false
local -r version_file="$1"
local this_plugin_supported=false

# check if current plugin is supported
for plugin in "${SUPPORTED_PLUGINS[@]}"; do
if [[ ${plugin} == "${THIS_PLUGIN}" ]]; then
this_plugin_supported=true
break
fi
done
# check if current plugin is supported
for plugin in "${SUPPORTED_PLUGINS[@]}"; do
if [[ ${plugin} == "${THIS_PLUGIN}" ]]; then
this_plugin_supported=true
break
fi
done

[[ ${this_plugin_supported} == false ]] && return 0
[[ ${this_plugin_supported} == false ]] && return 0

if [[ ${version_file} == *".${THIS_PLUGIN}-version" && -r ${version_file} ]]; then
cat "${version_file}"
elif [[ ${version_file} =~ ${ASDF_OPENTOFU_VERSION_FILE:-main.tofu} && -r ${version_file} ]]; then
read_version_from_main_tofu "${version_file}"
fi
if [[ ${version_file} == *".${THIS_PLUGIN}-version" && -r ${version_file} ]]; then
cat "${version_file}"
elif [[ ${version_file} =~ ${ASDF_OPENTOFU_VERSION_FILE:-main.tofu} && -r ${version_file} ]]; then
read_version_from_main_tofu "${version_file}"
fi
}

get_legacy_version "$1"

0 comments on commit d65ef27

Please sign in to comment.