-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from kamatama41/fix-pr-33
Fix PR 33
- Loading branch information
Showing
8 changed files
with
92 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
[ -n "$TFENV_DEBUG" ] && set -x | ||
echo "Usage: tfenv <command> [<options>] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
[ -n "$TFENV_DEBUG" ] && set -x | ||
|
||
if [ $# -ne 0 ];then | ||
echo "usage: tfenv list" 1>&2 | ||
function error_and_die() { | ||
echo -e "${1}" >&2 | ||
exit 1 | ||
fi | ||
} | ||
|
||
[ -n "$TFENV_DEBUG" ] && set -x | ||
|
||
[ $# -ne 0 ] \ | ||
&& error_and_die "usage: tfenv list" | ||
|
||
[ -d "${TFENV_ROOT}/versions" ] \ | ||
|| error_and_die "No versions available. Please install one with: tfenv install" | ||
|
||
set -e | ||
ls -1 "${TFENV_ROOT}/versions" | sort -t'.' -k 1nr,1 -k 2nr,2 -k 3nr,3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,37 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
[ -n "$TFENV_DEBUG" ] && set -x | ||
|
||
if [ $# -ne 1 ];then | ||
echo "usage: tfenv use <version>" 1>&2 | ||
function error_and_die() { | ||
echo -e "${1}" >&2 | ||
exit 1 | ||
fi | ||
} | ||
|
||
version="${1}" | ||
if [ -z "${version}" ];then | ||
echo "version is not specified" 1>&2 | ||
exit 1 | ||
[ -n "$TFENV_DEBUG" ] && set -x | ||
|
||
[ $# -ne 1 ] && error_and_die "usage: tfenv use <version>" | ||
|
||
declare version | ||
if [[ "${1}" =~ ^latest\:.*$ ]]; then | ||
version="${1%%\:*}" | ||
regex="${1##*\:}" | ||
else | ||
version="${1}" | ||
fi | ||
|
||
[ -d "${TFENV_ROOT}/versions" ] \ | ||
|| error_and_die "No versions of terraform installed. Please install one with: tfenv install" | ||
|
||
[ "${version}" == "latest" ] \ | ||
&& version="$(\ls "${TFENV_ROOT}/versions" \ | ||
| sort -t'.' -k 1nr,1 -k 2nr,2 -k 3nr,3 \ | ||
| grep -e "${regex}" \ | ||
| head -n 1 | ||
)" | ||
|
||
[ -n "${version}" ] || error_and_die "Version not specified or not found" | ||
|
||
target_path=${TFENV_ROOT}/versions/${version} | ||
if [ ! -f ${target_path}/terraform ];then | ||
echo "${version} is not installed" 1>&2 | ||
exit 1 | ||
fi | ||
[ -f ${target_path}/terraform ] \ | ||
|| error_and_die "Terraform version ${version} is not installed" | ||
|
||
echo "${version}" > "${TFENV_ROOT}/version" | ||
terraform --version | ||
terraform --version || error_and_die "'terraform --version' failed. Something is seriously wrong" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters