Skip to content

Commit

Permalink
Merge pull request #40 from devorbitus/accept-all-versions
Browse files Browse the repository at this point in the history
support for all terraform versions
  • Loading branch information
warrensbox authored May 16, 2019
2 parents 1611f13 + bd33aa2 commit ed66523
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/list_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func GetTFList(hashiURL string) ([]string, error) {

for i := range result {
//getting versions from body; should return match /X.X.X/
r, _ := regexp.Compile(`\/(\d+)(\.)(\d+)(\.)(\d+)\/`)
r, _ := regexp.Compile(`\/(\d+)(\.)(\d+)(\.)(\d+)(-\w+\d+)?\/`)

if r.MatchString(result[i]) {
str := r.FindString(result[i])
Expand Down Expand Up @@ -95,7 +95,7 @@ func RemoveDuplicateVersions(elements []string) []string {
// For example: The 0.1. 2 = invalid
func ValidVersionFormat(version string) bool {

semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}\z`)
semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}(-\w+\d+)?\z`)
semverRegex.MatchString(version)
return semverRegex.MatchString(version)
}
40 changes: 40 additions & 0 deletions lib/list_versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,44 @@ func TestValidVersionFormat(t *testing.T) {
log.Fatalf("Failed to verify version format: %s\n", version)
}

version = "1.11.9-beta1"

valid = lib.ValidVersionFormat(version)

if valid == true {
t.Log("Valid version format (expected)")
} else {
log.Fatalf("Failed to verify version format: %s\n", version)
}

version = "0.12.0-rc2"

valid = lib.ValidVersionFormat(version)

if valid == true {
t.Log("Valid version format (expected)")
} else {
log.Fatalf("Failed to verify version format: %s\n", version)
}

version = "1.11.4-boom"

valid = lib.ValidVersionFormat(version)

if valid == false {
t.Log("Invalid version format (expected)")
} else {
log.Fatalf("Failed to verify version format: %s\n", version)
}

version = "1.11.4-1"

valid = lib.ValidVersionFormat(version)

if valid == false {
t.Log("Invalid version format (expected)")
} else {
log.Fatalf("Failed to verify version format: %s\n", version)
}

}
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func main() {
lib.AddRecent(requestedVersion) //add to recent file for faster lookup
lib.Install(requestedVersion)
} else {
log.Println("Invalid terraform version format. Format should be #.#.# where # is a number. For example, 0.11.7 is a valid version")
log.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions")
}

} else {
log.Println("Invalid terraform version format. Format should be #.#.# where # is a number. For example, 0.11.7 is a valid version")
log.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions")
fmt.Println("Args must be a valid terraform version")
usageMessage()
}
Expand All @@ -93,7 +93,7 @@ func main() {
lib.AddRecent(string(tfversion)) //add to RECENT file for faster lookup
lib.Install(string(tfversion))
} else {
log.Println("Invalid terraform version format. Format should be #.#.# where # is a number. For example, 0.11.7 is a valid version")
log.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions")
os.Exit(1)
}
} else if len(args) == 0 { //if there are no commmand line arguments
Expand Down

0 comments on commit ed66523

Please sign in to comment.