-
Notifications
You must be signed in to change notification settings - Fork 116
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
tfinstall package #8
Conversation
WIP, reconsidering API |
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.
From high-level-API perspective I wonder if ExactPath
and LookPath
belong to this (tfinstall
) package.
Would it make sense to decouple those into tfdisco
and let the consumers decide about whether they want to couple them and how? At least in the language server I suspect I'd certainly use the discovery part, but far less likely the installation.
Thanks for the I've simplified the error handling logic along the lines suggested by @paultyng. Errors encountered during each strategy will now cause
|
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.
Sorry for the misunderstanding, but I was rather suggesting decoupling of "discovery" functions (i.e. LookPath
and ExactPath
) entirely to the tfdisco
package and leaving the installation functions (LatestVersion
, ExactVersion
) in tfinstall
.
I understand that the test framework needs the functionality "find or install", but I think that decision logic (whether to install) should either stay in the test framework or be decoupled to yet another layer if it really stays here.
e.g. I may want to do discovery earlier in the workflow, but install later, or something like that and the current coupling would make me do the discovery again, which seems unnecessary?
I don't quite understand your use case, and I'm reluctant to split into two packages here because I see this package as a natural grouping of |
The LS currently doesn't install Terraform, and I'm not sure when it will or how yet, but I'm assuming that we'd prompt the user to confirm the installation. In order to do that we'll need more flexibility around composing different parts of the library. I imagine the workflow would be something like
It's not that it's impossible, it's more the UX/API design that makes it difficult to expand and support more use cases, because it assumes that everyone will need both discovery and installation at the same time, which I don't think is true. Terraform can be installed outside of The discovery runs
I don't want to overburden you with all these different scenarios at such early stage though, because I think the initial implementation can be simple and doesn't need to satisfy all different use cases, but I do think that we should leave some room in the API so we can tweak it more easily to cater more use cases. With that in mind I'd be happy for the "find or install" logic to remain in the library, but it should be clear(er) upfront that this is what it does. Maybe you could turn type ExecutablePathFinder interface {
ExecPath() string
} and make each installer and discoverer comply with that interface? Then you'd use it like this: FirstExecutablePath(
tfdisco.ExactPath("/path/to/tf"),
tfdisco.LookPath(),
tfinstall.NewInstaller("latest"),
tfinstall.NewInstaller("0.12.28")) which leaves room for API surface growth on installer side, discovery side and the "coupling" side. |
0459d96
to
2fd1beb
Compare
I've reverted the package name to |
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.
LGTM, you may want to add some testing around pre-release versions.
Adds
tfinstall.Find(...*findOption) (string, error)
, which locates or downloads aterraform
binary according to the strategies provided. These are:ExactPath(execPath string)
Path to an existing
terraform
binary on the local filesystem.LookPath()
Attempt to locate a
terraform
binary on the local filesystem usingexec.LookPath()
.LatestVersion(installDir string)
Attempt to download the latest version of
terraform
and save it to the providedinstallDir
(if blank, a temporary directory will be created).ExactVersion(tfVersion string, installDir string)
As above, but will only download the exact provided version of
terraform
.Example
tfPath, err := tfinstall.Find(tfinstall.LookPath(), tfinstall.LatestVersion(""))
First,
tfinstall
will attempt to locateterraform
on the local system path. If found, this path will be returned astfPath
.If the executable is not found on the local system path,
tfinstall
will download the latest version ofterraform
and return the path to the downloaded executable astfPath
.An error is only returned if all provided strategies fail.