diff --git a/README.md b/README.md index b1355eb3..11bc0cc5 100644 --- a/README.md +++ b/README.md @@ -166,8 +166,14 @@ terraform_version_constraint = ">= 0.13, < 0.14" ... ``` -### Use custom mirror -To install from a remote mirror other than the default(https://releases.hashicorp.com/terraform). Use the `-m` or `--mirror` parameter. +### Gather the version from a subdirectory +```bash +tfswitch --chdir terraform +tfswitch -c terraform +``` + +### Use custom mirror +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` ## Automation diff --git a/main.go b/main.go index 6108f9e0..47bb8f5a 100644 --- a/main.go +++ b/main.go @@ -57,6 +57,7 @@ var version = "0.12.0\n" func main() { custBinPath := getopt.StringLong("bin", 'b', lib.ConvertExecutableExt(defaultBin), "Custom binary path. Ex: "+lib.ConvertExecutableExt("/Users/username/bin/terraform")) + chDirPath := getopt.StringLong("chdir", 'c', "Switch to a different working directory before executing the given command.") 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)") showLatestPre := getopt.StringLong("show-latest-pre", 'P', defaultLatest, "Show latest pre-release implicit version. Ex: tfswitch --show-latest-pre 0.13 prints 0.13.0-rc1 (latest)") @@ -78,6 +79,10 @@ func main() { os.Exit(1) } + if *chDirPath != "" { + dir = dir + "/" + *chDirPath + } + homedir, errHome := homedir.Dir() if errHome != nil { log.Printf("Failed to get home directory %v\n", errHome)