Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MatthewJohn
Copy link
Collaborator

@MatthewJohn MatthewJohn commented Jan 24, 2025

Issue #301

Copy link
Collaborator

@yermulnik yermulnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Should we deem feat: allow to show required by module version explicitly #301 obsolete and close in favour of this PR? (I'm closing that PR for now)
  • Do we need any tests for this new arg?
    • On a side note, we probably may need to look into restraining simultaneous use of cmdline args that are not compatible with each other (I mean this is a thought aloud)
  • I added commit suggestions to try and align this new arg with what it actually does (e.g. when version is provided via command line, this new arg does not show latest required, but outputs version requested on command line. same for version parameter in TOML. so on by means of all of the ifs from lib/param_parsing/parameters.go). WDYT?
  • Let me know if you'd like me to postpone new version release for --arch arg to get this PR added to the same release (or to cut next release for it later)

MirrorURL string
ShowLatestFlag bool
ShowLatestPre string
ShowLatestRequiredFlag bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Flag suffix looks pointless to me. Not sure what its value is and not sure why it was added to a few others in past. I guess the only exception are Version and VersionFlag (where both could have a more clear names though).
Would you mind removing this suffix so this new flag is in consistency with similar ones nearby?
Thanks.

Copy link
Collaborator

@yermulnik yermulnik Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ShowLatestRequiredFlag bool
ShowRequired bool

@@ -66,6 +67,7 @@ func populateParams(params Params) Params {
getopt.StringVarLong(&params.LogLevel, "log-level", 'g', "Set loglevel for tfswitch. One of (ERROR, INFO, NOTICE, DEBUG, TRACE)")
getopt.StringVarLong(&params.MirrorURL, "mirror", 'm', "install from a remote API other than the default. Default (based on product):\n"+strings.Join(defaultMirrors, "\n"))
getopt.BoolVarLong(&params.ShowLatestFlag, "show-latest", 'U', "Show latest stable version")
getopt.BoolVarLong(&params.ShowLatestRequiredFlag, "show-latest-required", 'R', "Show latest stable version, which complies to constraints set by Terraform/Terragrunt")
Copy link
Collaborator

@yermulnik yermulnik Jan 24, 2025

Choose a reason for hiding this comment

The 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.BoolVarLong(&params.ShowLatestRequiredFlag, "show-latest-required", 'R', "Show latest stable version, which complies to constraints set by Terraform/Terragrunt")
getopt.BoolVarLong(&params.ShowRequired, "show-required", 'R', "Show version, which complies to version requested by configuration")

@@ -177,6 +179,7 @@ func initParams(params Params) Params {
params.MirrorURL = ""
params.ShowLatestFlag = false
params.ShowLatestPre = lib.DefaultLatest
params.ShowLatestRequiredFlag = false
Copy link
Collaborator

@yermulnik yermulnik Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
params.ShowLatestRequiredFlag = false
params.ShowRequired = false

Comment on lines +68 to +70
case parameters.ShowLatestRequiredFlag:
/* show latest stable version within constraints */
lib.ShowLatestRequiredVersion(parameters.MirrorURL, parameters.Version)
Copy link
Collaborator

@yermulnik yermulnik Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case parameters.ShowLatestRequiredFlag:
/* show latest stable version within constraints */
lib.ShowLatestRequiredVersion(parameters.MirrorURL, parameters.Version)
case parameters.ShowRequired:
/* show version requested by configuration */
lib.ShowRequiredVersion(parameters.MirrorURL, parameters.Version)

Comment on lines +214 to +215
// ShowLatestRequiredVersion show latest version using constraints from TF
func ShowLatestRequiredVersion(mirrorURL string, version string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// ShowLatestRequiredVersion show latest version using constraints from TF
func ShowLatestRequiredVersion(mirrorURL string, version string) {
// ShowRequiredVersion show latest version using constraints from TF
func ShowRequiredVersion(mirrorURL string, version string) {

fmt.Printf("%s\n", version)
return
}
logger.Fatal("The provided terraform version does not exist.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.Fatal("The provided terraform version does not exist.")
logger.Fatalf("The requested version (%q) does not exist.", version)

@warrensbox
Copy link
Owner

warrensbox commented Jan 25, 2025

openAI

  • Should we deem feat: allow to show required by module version explicitly #301 obsolete and close in favour of this PR? (I'm closing that PR for now)

  • Do we need any tests for this new arg?

    • On a side note, we probably may need to look into restraining simultaneous use of cmdline args that are not compatible with each other (I mean this is a thought aloud)
  • I added commit suggestions to try and align this new arg with what it actually does (e.g. when version is provided via command line, this new arg does not show latest required, but outputs version requested on command line. same for version parameter in TOML. so on by means of all of the ifs from lib/param_parsing/parameters.go). WDYT?

  • Let me know if you'd like me to postpone new version release for --arch arg to get this PR added to the same release (or to cut next release for it later)

Do we need any tests for this new arg?

  • This would be ideal

On a side note, we probably may need to look into restraining simultaneous use of cmdline args that are not compatible with each other

  • I think we have had checks in the past to check this. It's worth checking this again

  • fair commit suggestions

Let me know if you'd like me to postpone new version release for --arch arg to get this PR added to the same release

  • I suggest 2 different releases, incase we need to roll back any of this new features

@yermulnik feel free to do the deployments for the release

@MatthewJohn
Copy link
Collaborator Author

Do we need any tests for this new arg?

Given the argument just prints to stdout and we don't have any mocking, I wonder if updating the function to return the string that is displayed to the user back to main.go might make this a lot easier? Without it, I'm not sure the easiest way to do it in golang.

On a side note, we probably may need to look into restraining simultaneous use of cmdline args that are not compatible with each other

The other argparsers I've seen have got this kind of functionality, but can't see viper does - assume it's something you had to do manually in the past?

I suggest 2 different releases, incase we need to roll back any of this new features

👍

I added commit suggestions to try and align this new arg...

Yes, I agree none of it makes much sense given it's high dependency on the argument parsing - it's somewhat of a shame that this is all done magically behind before the main case statement. Happy with any name, since it's just printing a pre-defined version argument.
Given all this, I can't see that the function is of much use at all as a third-party library (I guess, ideally it could be private).
If we do think it's completely unusued publicly, then maybe merging the function with ShowLatestVersion would make sense?

@yermulnik
Copy link
Collaborator

If we do think it's completely unusued publicly, then maybe merging the function with ShowLatestVersion would make sense?

I like the ShowRequired/ShowRequiredVersion naming as it reflects what this feature outputs. WDYT?

@yermulnik
Copy link
Collaborator

  • I suggest 2 different releases, incase we need to roll back any of this new features

@yermulnik feel free to do the deployments for the release

@warrensbox @MatthewJohn
I went with minor version bump: v1.3.0
Please review #539 and I'll cut v1.3.0 release once approved.

@yermulnik
Copy link
Collaborator

@MatthewJohn Will you be giving this PR some love? =)

@MatthewJohn
Copy link
Collaborator Author

MatthewJohn commented Feb 5, 2025 via email

@yermulnik
Copy link
Collaborator

Hey sorry, Had a little birth in the family - will take a look in tje next 24h when I’m next awake :)

Ah, congrats 🥳 Take your time and take some sleep =)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants