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

Default version flag added #275

Merged
merged 2 commits into from
Feb 6, 2023

Conversation

sivaramsajeev
Copy link
Contributor

This flag will allow us to specify a default version to install which will be useful for the CI systems instead of going into the prompt

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.

Could you please outline what's the difference wuth TF_VERSION env var (

terraform-switcher/main.go

Lines 209 to 213 in e77b48c

/* if Terraform Version environment variable is set */
case checkTFEnvExist() && len(args) == 0:
tfversion := os.Getenv("TF_VERSION")
fmt.Printf("Terraform version environment variable: %s\n", tfversion)
installVersion(tfversion, custBinPath, mirrorURL)
) and why TF_VERSION cannot suffice in your use case?
Thanks.

main.go Outdated Show resolved Hide resolved
Co-authored-by: George L. Yermulnik <yz@yz.kiev.ua>
@sivaramsajeev
Copy link
Contributor Author

sivaramsajeev commented Oct 12, 2022

@yermulnik In cases where TF_VERSION is already set (say for eg 1.2.4) in the environment, if we add TF_VERSION=1.2.3 tfswitch it'll install version 1.2.3 which is not intended. But tfswitch -d 1.2.3 can really act as a default version.
Thanks

@yermulnik
Copy link
Collaborator

@sivaramsajeev Aha, got you. The new option is intended to be a fallback.
Though could you please elaborate on how this is expected to work as I might be missing something essential since I'm not familiar with all code bits?
From what I see based on example with TF_VERSION: when this Env var is defined (let's suppose its value refers to a non-existing TF version so that fallback should be used) tfswitch triggers installVersion() function, which calls os.Exit(1) on errors (e.g. when requested TF version doesn't exist), which in its turn should interrupt tfswitch execution and hence would not return back into switch statement which handles command line options. What am I missing? 🤔

@sivaramsajeev
Copy link
Contributor Author

The --default option is just meant to be the version to be picked up if tfswicth is unable to get the intended version (Either the version is not set using one of the preceding methods OR tfswitch is unable to parse it ). This wont change the original behavior of exiting upon calling invalid version so it's not a fallback in that sense. It's also calling the same installVersion function.

TF_VERSION=x.x.x tfswicth won't act like default because it could potentially end up overriding the intended TF version env var. So if we give this one liner instead of something like tfswitch -d x.x.x, there is a chance that the intended TF version was also set by an environment variable explicitly or sourced during runtime & we end up overriding it with our one-liner.

@yermulnik
Copy link
Collaborator

yermulnik commented Oct 13, 2022

Either the version is not set using one of the preceding methods OR tfswitch is unable to parse it

Aah, I see now. This is the same as requested in #150 and #165 and actually is, broadly speaking, a programmatic implementation of "hackaround" from #165 (comment) (or echo x.x.x | tfswitch to select specific version the same way)
Yep, this makes sense to me. You got an approval from me, though @warrensbox and @jukie would better weigh in to review implementation details.

@warrensbox
Copy link
Owner

I am still reviewing this

@warrensbox warrensbox merged commit 5a95fbc into warrensbox:master Feb 6, 2023
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.

tfswitch should accept a "--non-interactive" argument Allow fallback version
3 participants