Skip to content

Commit 759a13a

Browse files
committed
Allow comments in .terraform-version file
Using syntax: # this whole line is a comment 1.2.3 # this is also a comment but not inline comments. Closes tfutils#283
1 parent 7898b72 commit 759a13a

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

lib/tfenv-version-name.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function tfenv-version-name() {
1010
&& log 'debug' "TFENV_VERSION_FILE retrieved from tfenv-version-file: ${TFENV_VERSION_FILE}" \
1111
|| log 'error' 'Failed to retrieve TFENV_VERSION_FILE from tfenv-version-file';
1212

13-
TFENV_VERSION="$(cat "${TFENV_VERSION_FILE}" || true)" \
13+
TFENV_VERSION="$(grep --invert-match '^#' "${TFENV_VERSION_FILE}" || true)" \
1414
&& log 'debug' "TFENV_VERSION specified in TFENV_VERSION_FILE: ${TFENV_VERSION}";
1515

1616
TFENV_VERSION_SOURCE="${TFENV_VERSION_FILE}";

libexec/tfenv-resolve-version

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ if [ -z "${arg}" -a -z "${TFENV_TERRAFORM_VERSION:-""}" ]; then
7777

7878
if [ "${version_file}" != "${TFENV_CONFIG_DIR}/version" ]; then
7979
log 'debug' "Version File (${version_file}) is not the default \${TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR}/version)";
80-
version_requested="$(cat "${version_file}")" \
80+
version_requested="$(grep --invert-match '^#' "${version_file}")" \
8181
|| log 'error' "Failed to open ${version_file}";
8282

8383
elif [ -f "${version_file}" ]; then
8484
log 'debug' "Version File is the default \${TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR}/version)";
85-
version_requested="$(cat "${version_file}")" \
85+
version_requested="$(grep --invert-match '^#' "${version_file}")" \
8686
|| log 'error' "Failed to open ${version_file}";
8787

8888
# Absolute fallback

libexec/tfenv-uninstall

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ if [ -z "${arg:-""}" -a -z "${TFENV_TERRAFORM_VERSION:-""}" ]; then
6969
log 'debug' "Version File: ${version_file}";
7070
if [ "${version_file}" != "${TFENV_CONFIG_DIR}/version" ]; then
7171
log 'debug' "Version File (${version_file}) is not the default \${TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR}/version)";
72-
version_requested="$(cat "${version_file}")" \
72+
version_requested="$(grep --invert-match '^#' "${version_file}")" \
7373
|| log 'error' "Failed to open ${version_file}";
7474
elif [ -f "${version_file}" ]; then
7575
log 'debug' "Version File is the default \${TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR}/version)";
76-
version_requested="$(cat "${version_file}")" \
76+
version_requested="$(grep --invert-match '^#' "${version_file}")" \
7777
|| log 'error' "Failed to open ${version_file}";
7878
else
7979
log 'debug' "Version File is the default \${TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR}/version) but it doesn't exist";

libexec/tfenv-use

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ if [ -z "${requested_arg}" -a -z "${TFENV_TERRAFORM_VERSION:-""}" ]; then
7676
version_source_suffix=" (set by ${loaded_version_file})";
7777

7878
if [ -f "${loaded_version_file}" ]; then
79-
requested="$(cat "${loaded_version_file}" || true)";
79+
requested="$(grep --invert-match '^#' "${loaded_version_file}" || true)";
8080
else
8181
# No-one asked for anything, no default version is set either
8282
requested='latest';

0 commit comments

Comments
 (0)