Skip to content

Commit

Permalink
Added more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
warrensbox committed Jun 5, 2019
1 parent a29bb2e commit 0cfc907
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
15 changes: 15 additions & 0 deletions lib/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
18 changes: 12 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
RELEASE_VERSION=0.6
RELEASE_VERSION=0.7

0 comments on commit 0cfc907

Please sign in to comment.