File tree Expand file tree Collapse file tree 6 files changed +21
-6
lines changed Expand file tree Collapse file tree 6 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -153,6 +153,7 @@ export -f check_dependencies;
153
153
154
154
source " $TFENV_ROOT /lib/tfenv-exec.sh" ;
155
155
source " $TFENV_ROOT /lib/tfenv-min-required.sh" ;
156
+ source " $TFENV_ROOT /lib/tfenv-parse-version-file.sh" ;
156
157
source " $TFENV_ROOT /lib/tfenv-version-file.sh" ;
157
158
source " $TFENV_ROOT /lib/tfenv-version-name.sh" ;
158
159
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ set -uo pipefail;
4
+
5
+ # Ensure GNU grep
6
+ check_dependencies;
7
+
8
+ function tfenv-parse-version-file() {
9
+ local version_file=" $1 "
10
+ log ' debug' " Parsing version from file ${version_file} "
11
+
12
+ grep --invert-match ' ^#' " ${version_file} " ;
13
+ }
14
+ export -f tfenv-parse-version-file;
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ function tfenv-version-name() {
10
10
&& log ' debug' " TFENV_VERSION_FILE retrieved from tfenv-version-file: ${TFENV_VERSION_FILE} " \
11
11
|| log ' error' ' Failed to retrieve TFENV_VERSION_FILE from tfenv-version-file' ;
12
12
13
- TFENV_VERSION=" $( grep --invert-match ' ^# ' " ${TFENV_VERSION_FILE} " || true ) " \
13
+ TFENV_VERSION=" $( tfenv-parse-version-file " ${TFENV_VERSION_FILE} " ) " \
14
14
&& log ' debug' " TFENV_VERSION specified in TFENV_VERSION_FILE: ${TFENV_VERSION} " ;
15
15
16
16
TFENV_VERSION_SOURCE=" ${TFENV_VERSION_FILE} " ;
Original file line number Diff line number Diff line change @@ -77,12 +77,12 @@ if [ -z "${arg}" -a -z "${TFENV_TERRAFORM_VERSION:-""}" ]; then
77
77
78
78
if [ " ${version_file} " != " ${TFENV_CONFIG_DIR} /version" ]; then
79
79
log ' debug' " Version File (${version_file} ) is not the default \$ {TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR} /version)" ;
80
- version_requested=" $( grep --invert-match ' ^# ' " ${version_file} " ) " \
80
+ version_requested=" $( tfenv-parse-version-file " ${version_file} " ) " \
81
81
|| log ' error' " Failed to open ${version_file} " ;
82
82
83
83
elif [ -f " ${version_file} " ]; then
84
84
log ' debug' " Version File is the default \$ {TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR} /version)" ;
85
- version_requested=" $( grep --invert-match ' ^# ' " ${version_file} " ) " \
85
+ version_requested=" $( tfenv-parse-version-file " ${version_file} " ) " \
86
86
|| log ' error' " Failed to open ${version_file} " ;
87
87
88
88
# Absolute fallback
Original file line number Diff line number Diff line change @@ -69,11 +69,11 @@ if [ -z "${arg:-""}" -a -z "${TFENV_TERRAFORM_VERSION:-""}" ]; then
69
69
log ' debug' " Version File: ${version_file} " ;
70
70
if [ " ${version_file} " != " ${TFENV_CONFIG_DIR} /version" ]; then
71
71
log ' debug' " Version File (${version_file} ) is not the default \$ {TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR} /version)" ;
72
- version_requested=" $( grep --invert-match ' ^# ' " ${version_file} " ) " \
72
+ version_requested=" $( tfenv-parse-version-file " ${version_file} " ) " \
73
73
|| log ' error' " Failed to open ${version_file} " ;
74
74
elif [ -f " ${version_file} " ]; then
75
75
log ' debug' " Version File is the default \$ {TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR} /version)" ;
76
- version_requested=" $( grep --invert-match ' ^# ' " ${version_file} " ) " \
76
+ version_requested=" $( tfenv-parse-version-file " ${version_file} " ) " \
77
77
|| log ' error' " Failed to open ${version_file} " ;
78
78
else
79
79
log ' debug' " Version File is the default \$ {TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR} /version) but it doesn't exist" ;
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ if [ -z "${requested_arg}" -a -z "${TFENV_TERRAFORM_VERSION:-""}" ]; then
76
76
version_source_suffix=" (set by ${loaded_version_file} )" ;
77
77
78
78
if [ -f " ${loaded_version_file} " ]; then
79
- requested=" $( grep --invert-match ' ^# ' " ${loaded_version_file} " || true ) " ;
79
+ requested=" $( tfenv-parse-version-file " ${loaded_version_file} " ) " ;
80
80
else
81
81
# No-one asked for anything, no default version is set either
82
82
requested=' latest' ;
You can’t perform that action at this time.
0 commit comments