From ca9922dd6781df02f4fbd292aa08e7ee5f7bdf7b Mon Sep 17 00:00:00 2001 From: Mike Peachey Date: Fri, 24 Apr 2026 16:30:06 +0100 Subject: [PATCH 1/2] Show architecture in tfenv list output tfenv list now displays the architecture of each installed binary: * 1.5.0 (amd64) (set by /path/to/version) 1.4.0 (arm64) Architecture is detected from the terraform binary using the file command. Supported architectures: amd64, arm64, 386, arm. Also updates the sed pattern in tfenv-uninstall to strip the new parenthesized arch from list output when matching versions. Fixes #321 --- libexec/tfenv-list | 23 +++++++++++++++++++++-- libexec/tfenv-uninstall | 2 +- test/test_list.sh | 21 +++++++++++++++------ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/libexec/tfenv-list b/libexec/tfenv-list index 3e50c51c..cd2197c5 100755 --- a/libexec/tfenv-list +++ b/libexec/tfenv-list @@ -84,12 +84,31 @@ export version_source; # Register for whether a default terraform version has yet been set declare -i default_set=0; +detect_arch() { + local binary="${1}"; + if [ ! -f "${binary}" ]; then + echo 'unknown'; + return; + fi; + local file_output; + file_output="$(file -b "${binary}" 2>/dev/null)" || { echo 'unknown'; return; }; + case "${file_output}" in + *x86-64*|*x86_64*) echo 'amd64';; + *aarch64*|*arm64*) echo 'arm64';; + *386*|*i386*|*80386*) echo '386';; + *ARM,*) echo 'arm';; + *) echo 'unknown';; + esac; +}; + print_version () { + local arch; + arch="$(detect_arch "${TFENV_CONFIG_DIR}/versions/${1}/terraform")"; if [ "${1}" == "${version_name}" ]; then - echo "* ${1} (set by ${version_source})"; + echo "* ${1} (${arch}) (set by ${version_source})"; default_set=1; else - echo " ${1}"; + echo " ${1} (${arch})"; fi; }; diff --git a/libexec/tfenv-uninstall b/libexec/tfenv-uninstall index 83289c85..df4236a4 100755 --- a/libexec/tfenv-uninstall +++ b/libexec/tfenv-uninstall @@ -112,7 +112,7 @@ fi; log 'debug' "Processing uninstall for version ${version}, using regex ${regex}"; -version="$(tfenv-list | sed -E 's/^(\*| )? //g; s/ \(set by .+\)$//' | grep -e "${regex}" | head -n 1)"; +version="$(tfenv-list | sed -E 's/^(\*| )? //g; s/ \([^)]+\)//g' | grep -e "${regex}" | head -n 1)"; [ -n "${version}" ] || log 'error' "No versions matching '${regex}' found in local"; dst_path="${TFENV_CONFIG_DIR}/versions/${version}"; diff --git a/test/test_list.sh b/test/test_list.sh index ae5b4b1e..c47977df 100755 --- a/test/test_list.sh +++ b/test/test_list.sh @@ -28,13 +28,22 @@ tfenv use 0.14.6; log 'info' '## Comparing "tfenv list" with default set'; result="$(tfenv list)"; + +# Determine expected arch from host platform +case "$(uname -m)" in + x86_64) expected_arch='amd64';; + aarch64|arm64) expected_arch='arm64';; + i386|i686) expected_arch='386';; + *) expected_arch='unknown';; +esac; + expected="$(cat << EOS -* 0.14.6 (set by $(tfenv version-file)) - 0.9.11 - 0.9.2 - 0.9.1 - 0.7.13 - 0.7.2 +* 0.14.6 (${expected_arch}) (set by $(tfenv version-file)) + 0.9.11 (${expected_arch}) + 0.9.2 (${expected_arch}) + 0.9.1 (${expected_arch}) + 0.7.13 (${expected_arch}) + 0.7.2 (${expected_arch}) EOS )"; From 7cf6ad17e543f79ccdbf56820e51c732b0ba610d Mon Sep 17 00:00:00 2001 From: Mike Peachey Date: Fri, 24 Apr 2026 16:44:51 +0100 Subject: [PATCH 2/2] Fix list test to detect arch per-binary, not from host On macOS arm64, older Terraform versions (pre-1.0) are amd64 binaries running under Rosetta. The test was using uname -m to predict the arch, which fails when installed binaries do not match the host architecture. Now uses the same file-based detection as tfenv-list itself. --- test/test_list.sh | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/test/test_list.sh b/test/test_list.sh index c47977df..790738b3 100755 --- a/test/test_list.sh +++ b/test/test_list.sh @@ -29,21 +29,28 @@ tfenv use 0.14.6; log 'info' '## Comparing "tfenv list" with default set'; result="$(tfenv list)"; -# Determine expected arch from host platform -case "$(uname -m)" in - x86_64) expected_arch='amd64';; - aarch64|arm64) expected_arch='arm64';; - i386|i686) expected_arch='386';; - *) expected_arch='unknown';; -esac; +# Detect arch from each installed binary — can't assume host arch +# because older versions may only have amd64 builds (e.g. macOS arm64 via Rosetta) +detect_arch() { + local binary="${1}"; + local file_output; + file_output="$(file -b "${binary}" 2>/dev/null)" || { echo 'unknown'; return; }; + case "${file_output}" in + *x86-64*|*x86_64*) echo 'amd64';; + *aarch64*|*arm64*) echo 'arm64';; + *386*|*i386*|*80386*) echo '386';; + *ARM,*) echo 'arm';; + *) echo 'unknown';; + esac; +}; expected="$(cat << EOS -* 0.14.6 (${expected_arch}) (set by $(tfenv version-file)) - 0.9.11 (${expected_arch}) - 0.9.2 (${expected_arch}) - 0.9.1 (${expected_arch}) - 0.7.13 (${expected_arch}) - 0.7.2 (${expected_arch}) +* 0.14.6 ($(detect_arch "${TFENV_CONFIG_DIR}/versions/0.14.6/terraform")) (set by $(tfenv version-file)) + 0.9.11 ($(detect_arch "${TFENV_CONFIG_DIR}/versions/0.9.11/terraform")) + 0.9.2 ($(detect_arch "${TFENV_CONFIG_DIR}/versions/0.9.2/terraform")) + 0.9.1 ($(detect_arch "${TFENV_CONFIG_DIR}/versions/0.9.1/terraform")) + 0.7.13 ($(detect_arch "${TFENV_CONFIG_DIR}/versions/0.7.13/terraform")) + 0.7.2 ($(detect_arch "${TFENV_CONFIG_DIR}/versions/0.7.2/terraform")) EOS )";