Skip to content

Commit

Permalink
Allow comments in .terraform-version file
Browse files Browse the repository at this point in the history
Using syntax:

    # this whole line is a comment
    1.2.3
    # this is also a comment

but not inline comments.

Closes #283
  • Loading branch information
OJFord committed Jul 15, 2022
1 parent 29131f3 commit 9c427c8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/tfenv-version-name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function tfenv-version-name() {
&& log 'debug' "TFENV_VERSION_FILE retrieved from tfenv-version-file: ${TFENV_VERSION_FILE}" \
|| log 'error' 'Failed to retrieve TFENV_VERSION_FILE from tfenv-version-file';

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

TFENV_VERSION_SOURCE="${TFENV_VERSION_FILE}";
Expand Down
4 changes: 2 additions & 2 deletions libexec/tfenv-resolve-version
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ if [ -z "${arg}" -a -z "${TFENV_TERRAFORM_VERSION:-""}" ]; then

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

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

# Absolute fallback
Expand Down
4 changes: 2 additions & 2 deletions libexec/tfenv-uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ if [ -z "${arg:-""}" -a -z "${TFENV_TERRAFORM_VERSION:-""}" ]; then
log 'debug' "Version File: ${version_file}";
if [ "${version_file}" != "${TFENV_CONFIG_DIR}/version" ]; then
log 'debug' "Version File (${version_file}) is not the default \${TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR}/version)";
version_requested="$(cat "${version_file}")" \
version_requested="$(grep --invert-match '^#' "${version_file}")" \
|| log 'error' "Failed to open ${version_file}";
elif [ -f "${version_file}" ]; then
log 'debug' "Version File is the default \${TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR}/version)";
version_requested="$(cat "${version_file}")" \
version_requested="$(grep --invert-match '^#' "${version_file}")" \
|| log 'error' "Failed to open ${version_file}";
else
log 'debug' "Version File is the default \${TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR}/version) but it doesn't exist";
Expand Down
2 changes: 1 addition & 1 deletion libexec/tfenv-use
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if [ -z "${requested_arg}" -a -z "${TFENV_TERRAFORM_VERSION:-""}" ]; then
version_source_suffix=" (set by ${loaded_version_file})";

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

0 comments on commit 9c427c8

Please sign in to comment.