Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
warrensbox committed Feb 5, 2021
1 parent 9838571 commit b959cef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ terraform {
```
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/versiontf.gif#1" alt="drawing" style="width: 370px;"/>


### Use environment variables
You can also set the `TF_VERSION` environment version to your desired terraform version.
For example:
```bash
export TF_VERSION=0.14.4
tfswitch #will automatically switch to terraform version 0.14.4
```
### Use .tfswitch.toml file (For non-admin - users with limited privilege on their computers)
This is similiar to using a .tfswitchrc file, but you can specify a custom binary path for your terraform installation

Expand Down
17 changes: 14 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,33 +106,44 @@ func main() {
}

switch {
/* GIVEN A TOML FILE, */
/* show all terraform version including betas and RCs*/
case *listAllFlag:
listAll := true //set list all true - all versions including beta and rc will be displayed
installOption(listAll, &binPath)
/* latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 (latest) */
case *latestPre != "":
preRelease := true
installLatestImplicitVersion(*latestPre, custBinPath, preRelease)
/* latest implicit version. Ex: tfswitch --latest 0.13 downloads 0.13.5 (latest) */
case *latestStable != "":
preRelease := false
installLatestImplicitVersion(*latestStable, custBinPath, preRelease)
/* latest stable version */
case *latestFlag:
installLatestVersion(custBinPath)
/* version provided on command line as arg */
case len(args) == 1:
installVersion(args[0], &binPath)
/* provide an tfswitchrc file (IN ADDITION TO A TOML FILE) */
case fileExists(RCFile) && len(args) == 0:
readingFileMsg(rcFilename)
tfversion := retrieveFileContents(RCFile)
installVersion(tfversion, &binPath)
/* if .terraform-version file found (IN ADDITION TO A TOML FILE) */
case fileExists(TFVersionFile) && len(args) == 0:
readingFileMsg(tfvFilename)
tfversion := retrieveFileContents(TFVersionFile)
installVersion(tfversion, &binPath)
/* if versions.tf file found (IN ADDITION TO A TOML FILE) */
case checkTFModuleFileExist(dir) && len(args) == 0:
installTFProvidedModule(dir, &binPath)
/* if Terraform Version environment variable is set */
case checkEnvExist() && len(args) == 0 && version == "":
tfversion := os.Getenv("TFVERSION")
tfversion := os.Getenv("TF_VERSION")
fmt.Printf("Terraform version environment variable: %s\n", tfversion)
installVersion(tfversion, custBinPath)
// if no arg is provided - but toml file is provided
case version != "":
installVersion(version, &binPath)
default:
Expand Down Expand Up @@ -180,7 +191,7 @@ func main() {

/* if Terraform Version environment variable is set */
case checkEnvExist() && len(args) == 0:
tfversion := os.Getenv("TFVERSION")
tfversion := os.Getenv("TF_VERSION")
fmt.Printf("Terraform version environment variable: %s\n", tfversion)
installVersion(tfversion, custBinPath)

Expand Down Expand Up @@ -286,7 +297,7 @@ func checkTFModuleFileExist(dir string) bool {
// fileExists checks if a file exists and is not a directory before we
// try using it to prevent further errors.
func checkEnvExist() bool {
tfversion := os.Getenv("TFVERSION")
tfversion := os.Getenv("TF_VERSION")
if tfversion != "" {
return true
}
Expand Down
7 changes: 7 additions & 0 deletions www/docs/Quick-Start.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ terraform {
```
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/versiontf.gif" alt="drawing" style="width: 600px;"/>

### Use environment variables
You can also set the `TF_VERSION` environment version to your desired terraform version.
For example:
```bash
export TF_VERSION=0.14.4
tfswitch #will automatically switch to terraform version 0.14.4
```
### Use .tfswitch.toml file (For non-admin - users with limited privilege on their computers)
This is similiar to using a .tfswitchrc file, but you can specify a custom binary path for your terraform installation

Expand Down

0 comments on commit b959cef

Please sign in to comment.