Skip to content

Commit

Permalink
style: shfmt bin/list-legacy-filenames (#44)
Browse files Browse the repository at this point in the history
Fix #41
  • Loading branch information
virtualroot authored Sep 19, 2024
1 parent 1009a22 commit 3f21691
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 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"
4 changes: 3 additions & 1 deletion scripts/format.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash

shfmt --language-dialect bash --write \
./**/*
./bin/* \
./lib/* \
./scripts/*
4 changes: 3 additions & 1 deletion scripts/lint.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ shellcheck --shell=bash --external-sources \
scripts/*

shfmt --language-dialect bash --diff \
./**/*
./bin/* \
./lib/* \
./scripts/*

0 comments on commit 3f21691

Please sign in to comment.