Skip to content

Commit

Permalink
Simplify installFromConstraint
Browse files Browse the repository at this point in the history
  • Loading branch information
jb-abbadie committed Sep 30, 2021
1 parent 635813b commit 9e6891b
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions pkg/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,26 @@ func installFromConstraint(tfconstraint *string, mirrorURL string) string {
}

sort.Sort(sort.Reverse(semver.Collection(versions)))

for _, element := range versions {
if constrains.Check(element) { // Validate a version against a constraint
tfversion := element.String()
if ValidVersionFormat(tfversion) { // check if version format is correct
out, err := Install(tfversion, mirrorURL)
if err != nil {
log.Printf("Error during install %v", err)
os.Exit(1)
}

return out
}
log.Errorf("Invalid terraform version format.")
// Validate a version against a constraint
if !constrains.Check(element) {
continue
}
tfversion := element.String()

// check if version format is correct
if !ValidVersionFormat(tfversion) {
log.Debugf("Version not with invalid format %v", tfversion)

continue
}
out, err := Install(tfversion, mirrorURL)
if err != nil {
log.Printf("Error during install %v", err)
os.Exit(1)
}

return out
}

log.Errorf("No version found to match constraint. Follow the README.md instructions for setup. https://github.com/terraform-tools/simple-tfswitch/blob/main/README.md")
Expand Down

0 comments on commit 9e6891b

Please sign in to comment.