tenv requires Go version 1.23 or above.
tenvlib package is available since tenv v3.2
go get -u github.com/tofuutils/tenv/v4@latestpackage main
import (
"context"
"fmt"
"github.com/tofuutils/tenv/v4/config/cmdconst"
"github.com/tofuutils/tenv/v4/versionmanager/tenvlib"
)
func main() {
tenv, err := tenvlib.Make(tenvlib.AutoInstall, tenvlib.IgnoreEnv, tenvlib.DisableDisplay)
if err != nil {
fmt.Println("init failed :", err)
return
}
err = tenv.DetectedCommandProxy(context.Background(), cmdconst.TofuName, "version")
if err != nil {
fmt.Println("proxy call failed :", err)
}
}See the API documentation on go.dev and examples.
Available Tenv struct creation options :
AddTool(toolName string, builderFunc builder.BuilderFunc), extendtenvlibto support other tool use cases.AutoInstall, shortcut to force auto install feature enabling inconfig.Config.DisableDisplay, do not display or log anything.IgnoreEnv, ignore tenv environment variables (TENV_AUTO_INSTALL,TOFUENV_TOFU_VERSION, etc.).WithConfig(conf *config.Config), replace defaultConfig(one from aInitConfigFromEnvorDefaultConfigcall depending onIgnoreEnvusage).WithDisplayer(displayer loghelper.Displayer), replace defaultDisplayerwith a custom to handletenvliboutput (standard and log).WithHCLParser(hclParser *hclparse.Parser), use passedParserinstead of creating a new one.
Tenv methods list :
[Detected]Command[Proxy]DetectEvaluateInstall[Multiple]List[Local|Remote]LocallyInstalled[Res|S]etDefault[Constraint|Version], manageconstraintandversionfiles in<rootPath>/<tool>/Uninstall[Multiple]
Happy hacking !