diff --git a/lib/files.go b/lib/files.go index 81d63726..06846509 100644 --- a/lib/files.go +++ b/lib/files.go @@ -201,3 +201,18 @@ func CheckDirHasTGBin(dir, prefix string) bool { } return exist } + +//CheckDirExist : check if directory exist +func CheckDirExist(dir string) error { + if _, err := os.Stat(dir); os.IsNotExist(err) { + return err + } + + return nil +} + +// Path : removes base directory +func Path(value string) string { + + return filepath.Dir(value) +} diff --git a/main.go b/main.go index f06a5698..f4153fb9 100644 --- a/main.go +++ b/main.go @@ -33,13 +33,13 @@ const ( hashiURL = "https://releases.hashicorp.com/terraform/" ) -var version = "0.6.0\n" +var version = "0.7.0\n" func main() { - custBinPath := getopt.StringLong("bin", 'b', "/usr/local/bin/terraform", "custom binary path") - listAllFlag := getopt.BoolLong("list-all", 'l', "list all versions of terraform - including beta and rc") - versionFlag := getopt.BoolLong("version", 'v', "displays the version of tfswitch") - helpFlag := getopt.BoolLong("help", 'h', "displays help message") + custBinPath := getopt.StringLong("bin", 'b', "/usr/local/bin/terraform", "Custom binary path. For example: /Users/username/bin/terraform") + listAllFlag := getopt.BoolLong("list-all", 'l', "List all versions of terraform - including beta and rc") + versionFlag := getopt.BoolLong("version", 'v', "Displays the version of tfswitch") + helpFlag := getopt.BoolLong("help", 'h', "Displays help message") _ = versionFlag getopt.Parse() @@ -52,7 +52,13 @@ func main() { } rcfile := dir + "/.tfswitchrc" - fmt.Println(*custBinPath) + errBinDirExist := lib.CheckDirExist(lib.Path(*custBinPath)) + + if errBinDirExist != nil { + fmt.Printf("Binary path does not exist: %s\n", lib.Path(*custBinPath)) + fmt.Printf("Please create binary path: %s for terraform installation\n", lib.Path(*custBinPath)) + os.Exit(1) + } if *versionFlag { fmt.Printf("\nVersion: %v\n", version) diff --git a/version b/version index bb82e304..37f085c6 100644 --- a/version +++ b/version @@ -1 +1 @@ -RELEASE_VERSION=0.6 \ No newline at end of file +RELEASE_VERSION=0.7 \ No newline at end of file