Skip to content

Commit

Permalink
Add error return values to signatures of public methods to allow migr…
Browse files Browse the repository at this point in the history
…ating to returning errors rather than Fatals in future
  • Loading branch information
MatthewJohn committed Jun 8, 2024
1 parent e25a6bc commit 09975ed
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func InstallLatestImplicitVersion(dryRun bool, requestedVersion, customBinaryPat
}

// InstallLatestProductImplicitVersion install latest - argument (version) must be provided
func InstallLatestProductImplicitVersion(product Product, dryRun bool, requestedVersion, customBinaryPath, installPath string, mirrorURL string, preRelease bool) {
func InstallLatestProductImplicitVersion(product Product, dryRun bool, requestedVersion, customBinaryPath, installPath string, mirrorURL string, preRelease bool) error {
_, err := version.NewConstraint(requestedVersion)
if err != nil {
logger.Errorf("Error parsing constraint %q: %v", requestedVersion, err)
Expand All @@ -223,6 +223,7 @@ func InstallLatestProductImplicitVersion(product Product, dryRun bool, requested
}
logger.Errorf("Error parsing constraint %q: %v", requestedVersion, err)
PrintInvalidMinorTFVersion()
return nil
}

// InstallVersion install Terraform product
Expand All @@ -234,7 +235,7 @@ func InstallVersion(dryRun bool, version, customBinaryPath, installPath, mirrorU
}

// InstallProductVersion install with provided version as argument
func InstallProductVersion(product Product, dryRun bool, version, customBinaryPath, installPath, mirrorURL string) {
func InstallProductVersion(product Product, dryRun bool, version, customBinaryPath, installPath, mirrorURL string) error {
logger.Debugf("Install version %s. Dry run: %s", version, strconv.FormatBool(dryRun))
if !dryRun {
if validVersionFormat(version) {
Expand All @@ -248,7 +249,7 @@ func InstallProductVersion(product Product, dryRun bool, version, customBinaryPa
ChangeProductSymlink(product, installFileVersionPath, customBinaryPath)
logger.Infof("Switched %s to version %q", product.GetName(), requestedVersion)
addRecent(requestedVersion, installPath, product) //add to recent file for faster lookup
return
return nil
}

// If the requested version had not been downloaded before
Expand All @@ -268,6 +269,7 @@ func InstallProductVersion(product Product, dryRun bool, version, customBinaryPa
os.Exit(1)
}
}
return nil
}

// InstallProductOption displays & installs tf version
Expand All @@ -288,7 +290,7 @@ type VersionSelector struct {
// InstallProductOption displays & installs tf version
/* listAll = true - all versions including beta and rc will be displayed */
/* listAll = false - only official stable release are displayed */
func InstallProductOption(product Product, listAll, dryRun bool, customBinaryPath, installPath string, mirrorURL string) {
func InstallProductOption(product Product, listAll, dryRun bool, customBinaryPath, installPath string, mirrorURL string) error {
var selectVersions []VersionSelector

var versionMap map[string]bool = make(map[string]bool)
Expand Down Expand Up @@ -347,4 +349,5 @@ func InstallProductOption(product Product, listAll, dryRun bool, customBinaryPat
install(product, selectVersions[selectedItx].Version, customBinaryPath, installPath, mirrorURL)
}
os.Exit(0)
return nil
}

0 comments on commit 09975ed

Please sign in to comment.