-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add show latest command that prints latest version that conform to contraints #536
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -205,12 +205,27 @@ func validMinorVersionFormat(version string) bool { | |||||
return semverRegex.MatchString(version) | ||||||
} | ||||||
|
||||||
// ShowLatestVersion show install latest stable tf version | ||||||
// ShowLatestVersion show latest stable tf version | ||||||
func ShowLatestVersion(mirrorURL string) { | ||||||
tfversion, _ := getTFLatest(mirrorURL) | ||||||
fmt.Printf("%s\n", tfversion) | ||||||
} | ||||||
|
||||||
// ShowLatestRequiredVersion show latest version using constraints from TF | ||||||
func ShowLatestRequiredVersion(mirrorURL string, version string) { | ||||||
if version == "" { | ||||||
ShowLatestVersion(mirrorURL) | ||||||
return | ||||||
} | ||||||
// Ensure version passed in valid and didn't come from an argument | ||||||
tflist, _ := getTFList(mirrorURL, true) | ||||||
if versionExist(version, tflist) { | ||||||
fmt.Printf("%s\n", version) | ||||||
return | ||||||
} | ||||||
logger.Fatal("The provided terraform version does not exist.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
// ShowLatestImplicitVersion show latest - argument (version) must be provided | ||||||
func ShowLatestImplicitVersion(requestedVersion, mirrorURL string, preRelease bool) { | ||||||
if validMinorVersionFormat(requestedVersion) { | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,27 +12,28 @@ import ( | |||||
) | ||||||
|
||||||
type Params struct { | ||||||
Arch string | ||||||
ChDirPath string | ||||||
CustomBinaryPath string | ||||||
DefaultVersion string | ||||||
DryRun bool | ||||||
HelpFlag bool | ||||||
InstallPath string | ||||||
LatestFlag bool | ||||||
LatestPre string | ||||||
LatestStable string | ||||||
ListAllFlag bool | ||||||
LogLevel string | ||||||
MirrorURL string | ||||||
ShowLatestFlag bool | ||||||
ShowLatestPre string | ||||||
ShowLatestStable string | ||||||
Product string | ||||||
ProductEntity lib.Product | ||||||
TomlDir string | ||||||
Version string | ||||||
VersionFlag bool | ||||||
Arch string | ||||||
ChDirPath string | ||||||
CustomBinaryPath string | ||||||
DefaultVersion string | ||||||
DryRun bool | ||||||
HelpFlag bool | ||||||
InstallPath string | ||||||
LatestFlag bool | ||||||
LatestPre string | ||||||
LatestStable string | ||||||
ListAllFlag bool | ||||||
LogLevel string | ||||||
MirrorURL string | ||||||
ShowLatestFlag bool | ||||||
ShowLatestPre string | ||||||
ShowLatestRequiredFlag bool | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
ShowLatestStable string | ||||||
Product string | ||||||
ProductEntity lib.Product | ||||||
TomlDir string | ||||||
Version string | ||||||
VersionFlag bool | ||||||
} | ||||||
|
||||||
var logger *slog.Logger | ||||||
|
@@ -66,6 +67,7 @@ func populateParams(params Params) Params { | |||||
getopt.StringVarLong(¶ms.LogLevel, "log-level", 'g', "Set loglevel for tfswitch. One of (ERROR, INFO, NOTICE, DEBUG, TRACE)") | ||||||
getopt.StringVarLong(¶ms.MirrorURL, "mirror", 'm', "install from a remote API other than the default. Default (based on product):\n"+strings.Join(defaultMirrors, "\n")) | ||||||
getopt.BoolVarLong(¶ms.ShowLatestFlag, "show-latest", 'U', "Show latest stable version") | ||||||
getopt.BoolVarLong(¶ms.ShowLatestRequiredFlag, "show-latest-required", 'R', "Show latest stable version, which complies to constraints set by Terraform/Terragrunt") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Terraform/Terragrunt and OpenTofu and by other allowed means like TOML file =)
Suggested change
|
||||||
getopt.StringVarLong(¶ms.ShowLatestPre, "show-latest-pre", 'P', "Show latest pre-release implicit version. Ex: tfswitch --show-latest-pre 0.13 prints 0.13.0-rc1 (latest)") | ||||||
getopt.StringVarLong(¶ms.ShowLatestStable, "show-latest-stable", 'S', "Show latest implicit version. Ex: tfswitch --show-latest-stable 0.13 prints 0.13.7 (latest)") | ||||||
getopt.StringVarLong(¶ms.Product, "product", 't', fmt.Sprintf("Specifies which product to use. Ex: `tfswitch --product opentofu` will install OpenTofu. Options: (%s). Default: %s", strings.Join(productIds, ", "), lib.DefaultProductId)) | ||||||
|
@@ -177,6 +179,7 @@ func initParams(params Params) Params { | |||||
params.MirrorURL = "" | ||||||
params.ShowLatestFlag = false | ||||||
params.ShowLatestPre = lib.DefaultLatest | ||||||
params.ShowLatestRequiredFlag = false | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
params.ShowLatestStable = lib.DefaultLatest | ||||||
params.TomlDir = lib.GetHomeDirectory() | ||||||
params.Version = lib.DefaultLatest | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -65,6 +65,9 @@ func main() { | |||||||||||||
case parameters.ShowLatestFlag: | ||||||||||||||
/* show latest stable version */ | ||||||||||||||
lib.ShowLatestVersion(parameters.MirrorURL) | ||||||||||||||
case parameters.ShowLatestRequiredFlag: | ||||||||||||||
/* show latest stable version within constraints */ | ||||||||||||||
lib.ShowLatestRequiredVersion(parameters.MirrorURL, parameters.Version) | ||||||||||||||
Comment on lines
+68
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
case parameters.Version != "": | ||||||||||||||
err = lib.InstallProductVersion(parameters.ProductEntity, parameters.DryRun, parameters.Version, parameters.CustomBinaryPath, parameters.InstallPath, parameters.MirrorURL, parameters.Arch) | ||||||||||||||
case parameters.DefaultVersion != "": | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.