Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:warrensbox/terraform-switcher in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
warrensbox committed May 29, 2018
2 parents a645def + 1e34627 commit 54285d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/symlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func RemoveSymlink(symlinkPath string) {

_, err := os.Lstat(symlinkPath)
if err != nil {
log.Fatal("Unable to remove symlink. You must have SUDO privileges")
log.Fatalf("Unable to find symlink. You must have SUDO privileges - %v \n", err)
panic(err)
} else {
errRemove := os.Remove(symlinkPath)
if errRemove != nil {
log.Fatal("Unable to remove symlink. You must have SUDO privileges")
log.Fatalf("Unable to remove symlink. You must have SUDO privileges - %v \n", err)
panic(errRemove)
}
}
Expand Down
22 changes: 18 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,15 @@ func main() {

/* if selected version already exist, */
if fileExist {
/* remove current symlink and set new symlink to desired version */
lib.RemoveSymlink(installedBinPath)
/* remove current symlink if exist*/
exist := lib.CheckFileExist(installedBinPath)

if !exist {
fmt.Println("Symlink does not exist")
} else {
fmt.Printf("Symlink exist")
lib.RemoveSymlink(installedBinPath)
}

/* set symlink to desired version */
lib.CreateSymlink(installLocation+installVersion+version, installedBinPath)
Expand Down Expand Up @@ -176,8 +183,15 @@ func main() {
/* remove zipped file to clear clutter */
lib.RemoveFiles(installLocation + installVersion + version + "_" + goos + "_" + goarch + ".zip")

/* remove current symlink and set new symlink to desired version */
lib.RemoveSymlink(installedBinPath)
/* remove current symlink if exist*/
exist := lib.CheckFileExist(installedBinPath)

if !exist {
fmt.Println("Symlink does not exist")
} else {
fmt.Printf("Symlink exist")
lib.RemoveSymlink(installedBinPath)
}

/* set symlink to desired version */
lib.CreateSymlink(installLocation+installVersion+version, installedBinPath)
Expand Down

0 comments on commit 54285d9

Please sign in to comment.