Skip to content

Commit

Permalink
Merge pull request #245 from warrensbox/master
Browse files Browse the repository at this point in the history
Release 0.13 - Minor release
  • Loading branch information
warrensbox committed May 27, 2022
2 parents ed7e986 + 6583c47 commit 8a41cc2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 35 deletions.
15 changes: 8 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ version: 2.1
jobs:
build:
docker:
- image: circleci/golang:1.16
- image: cimg/go:1.18

working_directory: /go/src/github.com/warrensbox/terraform-switcher
working_directory: /home/circleci/go/src/github.com/warrensbox/terraform-switcher

steps:
- checkout
- run:
command: |
set +e
echo "Building website"
sudo apt-get install python3
sudo apt-get install python3-pip
echo "Building website"
sudo apt-get update
sudo apt-get install python3 python3-pip
pip3 install mkdocs-material
cd www
mkdocs gh-deploy --force
Expand All @@ -28,12 +28,13 @@ jobs:
go test -v ./...
mkdir -p build
go build -v -o build/tfswitch
find ./test-data/* -type d | xargs -n 1 ./build/tfswitch -c
release:
docker:
- image: circleci/golang:1.16
- image: cimg/go:1.18

working_directory: /go/src/github.com/warrensbox/terraform-switcher
working_directory: /home/circleci/go/src/github.com/warrensbox/terraform-switcher

steps:
- checkout
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ brews:

# Caveats for the user of your binary.
# Default is empty.
caveats: "Type 'tfswitch' on your command line and choose the terraform version that you want from the dropdown. This command currently only works on MacOs and Linux"
caveats: "Type 'tfswitch' on your command line and choose the terraform version that you want from the dropdown. This command currently only works on macOS and Linux"

# Your app's homepage.
# Default is empty.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
EXE := tfswitch
PKG := github.com/warrensbox/terraform-switcher
VER := $(shell git ls-remote --tags git://github.com/warrensbox/terraform-switcher | awk '{print $$2}'| awk -F"/" '{print $$3}' | sort -n -t. -k1,1 -k2,2 -k3,3 | tail -n 2 | head -n1)
VER := $(shell git ls-remote --tags git@github.com:warrensbox/terraform-switcher.git | awk '{if ($$2 ~ "\\^\\{\\}$$") next; print vers[split($$2,vers,"\\/")]}' | sort -n -t. -k1,1 -k2,2 -k3,3 | tail -1)
PATH := build:$(PATH)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
Expand Down
34 changes: 25 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
module github.com/warrensbox/terraform-switcher

go 1.13
go 1.18

require (
github.com/chzyer/logex v1.1.10 // indirect
github.com/chzyer/readline v0.0.0-20171208011716-f6d7a1f6fbf3 // indirect
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
github.com/hashicorp/go-version v1.4.0
github.com/hashicorp/hcl2 v0.0.0-20191002203319-fb75b3253c80
github.com/hashicorp/terraform-config-inspect v0.0.0-20211115214459-90acf1ca460f
github.com/manifoldco/promptui v0.2.2-0.20180308161052-c0c0d3afc6a0
github.com/mitchellh/go-homedir v1.1.0
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30
github.com/spf13/viper v1.4.0
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
)

require (
github.com/agext/levenshtein v1.2.2 // indirect
github.com/apparentlymart/go-textseg v1.0.0 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/chzyer/logex v1.1.10 // indirect
github.com/chzyer/readline v0.0.0-20171208011716-f6d7a1f6fbf3 // indirect
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/google/go-cmp v0.3.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.0.0 // indirect
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect
github.com/lunixbochs/vtclean v0.0.0-20170504063817-d14193dfc626 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/manifoldco/promptui v0.2.2-0.20180308161052-c0c0d3afc6a0
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.3 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/pelletier/go-toml v1.4.0 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.4.0
github.com/spf13/pflag v1.0.3 // indirect
github.com/zclconf/go-cty v1.8.0 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
golang.org/x/text v0.3.5 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
)
28 changes: 12 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
var version = "0.12.0\n"

func main() {
dir := lib.GetCurrentDirectory()
custBinPath := getopt.StringLong("bin", 'b', lib.ConvertExecutableExt(defaultBin), "Custom binary path. Ex: tfswitch -b "+lib.ConvertExecutableExt("/Users/username/bin/terraform"))
listAllFlag := getopt.BoolLong("list-all", 'l', "List all versions of terraform - including beta and rc")
latestPre := getopt.StringLong("latest-pre", 'p', defaultLatest, "Latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 (latest)")
Expand All @@ -59,27 +60,22 @@ func main() {
showLatestStable := getopt.StringLong("show-latest-stable", 'S', defaultLatest, "Show latest implicit version. Ex: tfswitch --show-latest-stable 0.13 prints 0.13.7 (latest)")
latestFlag := getopt.BoolLong("latest", 'u', "Get latest stable version")
showLatestFlag := getopt.BoolLong("show-latest", 'U', "Show latest stable version")
mirrorURL := getopt.StringLong("mirror", 'm', defaultMirror, "Install from a remote other than the default. Default: https://releases.hashicorp.com/terraform")
chDirPath := getopt.StringLong("chdir", 'c', "", "Switch to a different working directory before executing the given command. Ex: tfswitch --chdir terraform_project will run tfswitch in the terraform_project directory")
mirrorURL := getopt.StringLong("mirror", 'm', defaultMirror, "Install from a remote API other than the default. Default: "+defaultMirror)
chDirPath := getopt.StringLong("chdir", 'c', dir, "Switch to a different working directory before executing the given command. Ex: tfswitch --chdir terraform_project will run tfswitch in the terraform_project directory")
versionFlag := getopt.BoolLong("version", 'v', "Displays the version of tfswitch")
helpFlag := getopt.BoolLong("help", 'h', "Displays help message")
_ = versionFlag

getopt.Parse()
args := getopt.Args()

dir := lib.GetCurrentDirectory()
homedir := lib.GetHomeDirectory()

if *chDirPath != "" {
dir = dir + "/" + *chDirPath
}

TFVersionFile := filepath.Join(dir, tfvFilename) //settings for .terraform-version file in current directory (tfenv compatible)
RCFile := filepath.Join(dir, rcFilename) //settings for .tfswitchrc file in current directory (backward compatible purpose)
TOMLConfigFile := filepath.Join(dir, tomlFilename) //settings for .tfswitch.toml file in current directory (option to specify bin directory)
TFVersionFile := filepath.Join(*chDirPath, tfvFilename) //settings for .terraform-version file in current directory (tfenv compatible)
RCFile := filepath.Join(*chDirPath, rcFilename) //settings for .tfswitchrc file in current directory (backward compatible purpose)
TOMLConfigFile := filepath.Join(*chDirPath, tomlFilename) //settings for .tfswitch.toml file in current directory (option to specify bin directory)
HomeTOMLConfigFile := filepath.Join(homedir, tomlFilename) //settings for .tfswitch.toml file in home directory (option to specify bin directory)
TGHACLFile := filepath.Join(dir, tgHclFilename) //settings for terragrunt.hcl file in current directory (option to specify bin directory)
TGHACLFile := filepath.Join(*chDirPath, tgHclFilename) //settings for terragrunt.hcl file in current directory (option to specify bin directory)

switch {
case *versionFlag:
Expand All @@ -99,7 +95,7 @@ func main() {
version := ""
binPath := *custBinPath
if fileExists(TOMLConfigFile) { //read from toml from current directory
version, binPath = getParamsTOML(binPath, dir)
version, binPath = getParamsTOML(binPath, *chDirPath)
} else { // else read from toml from home directory
version, binPath = getParamsTOML(binPath, homedir)
}
Expand Down Expand Up @@ -135,8 +131,8 @@ func main() {
tfversion := retrieveFileContents(TFVersionFile)
installVersion(tfversion, &binPath, mirrorURL)
/* if versions.tf file found (IN ADDITION TO A TOML FILE) */
case checkTFModuleFileExist(dir) && len(args) == 0:
installTFProvidedModule(dir, &binPath, mirrorURL)
case checkTFModuleFileExist(*chDirPath) && len(args) == 0:
installTFProvidedModule(*chDirPath, &binPath, mirrorURL)
/* if Terraform Version environment variable is set */
case checkTFEnvExist() && len(args) == 0 && version == "":
tfversion := os.Getenv("TF_VERSION")
Expand Down Expand Up @@ -202,8 +198,8 @@ func main() {
installVersion(tfversion, custBinPath, mirrorURL)

/* if versions.tf file found */
case checkTFModuleFileExist(dir) && len(args) == 0:
installTFProvidedModule(dir, custBinPath, mirrorURL)
case checkTFModuleFileExist(*chDirPath) && len(args) == 0:
installTFProvidedModule(*chDirPath, custBinPath, mirrorURL)

/* if terragrunt.hcl file found */
case fileExists(TGHACLFile) && checkVersionDefinedHCL(&TGHACLFile) && len(args) == 0:
Expand Down
2 changes: 1 addition & 1 deletion test-data/test_tfswitchtoml/.tfswitch.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bin = "/Users/warrenveerasingam/bin/terraform"
bin = "/usr/local/bin/terraform"
version = "0.11.3"

0 comments on commit 8a41cc2

Please sign in to comment.