Skip to content

Commit

Permalink
Default version flag added
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaramsajeev committed Oct 11, 2022
1 parent ef92e9a commit e77b48c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ tfswitch -c terraform_dir
To install from a remote mirror other than the default(https://releases.hashicorp.com/terraform). Use the `-m` or `--mirror` parameter.
Ex: `tfswitch --mirror https://example.jfrog.io/artifactory/hashicorp`

### Set a default TF version to pick
1. Help the CI systems to default to a version in case version is not detected from above steps.
2. Ex: `tfswitch -d 1.2.3` or `tfswitch --default 1.2.3` installs version `1.2.3` in case no other versions could be detected.
3. Hit **Enter** to install.

## Automation
**Automatically switch with bash**

Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func main() {
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")
defaultVersion := getopt.StringLong("default", 'd', defaultLatest, "Default to version to pick up. Ex: tfswitch --default 1.2.4")
helpFlag := getopt.BoolLong("help", 'h', "Displays help message")
_ = versionFlag

Expand Down Expand Up @@ -211,6 +212,10 @@ func main() {
fmt.Printf("Terraform version environment variable: %s\n", tfversion)
installVersion(tfversion, custBinPath, mirrorURL)

/* if default version is provided - Pick this instead of going for prompt */
case *defaultVersion != "":
installVersion(*defaultVersion, custBinPath, mirrorURL)

// if no arg is provided
default:
listAll := false //set list all false - only official release will be displayed
Expand Down

0 comments on commit e77b48c

Please sign in to comment.