tenv requires Go version 1.23 or above.
tenvlib
package is available since tenv v3.2
go get -u github.com/tofuutils/tenv/v3@latest
package main
import (
"context"
"fmt"
"github.com/tofuutils/tenv/v3/config/cmdconst"
"github.com/tofuutils/tenv/v3/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)
, extendtenvlib
to 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 aInitConfigFromEnv
orDefaultConfig
call depending onIgnoreEnv
usage).WithDisplayer(displayer loghelper.Displayer)
, replace defaultDisplayer
with a custom to handletenvlib
output (standard and log).WithHCLParser(hclParser *hclparse.Parser)
, use passedParser
instead of creating a new one.
Tenv methods list :
[Detected]Command[Proxy]
Detect
Evaluate
Install[Multiple]
List[Local|Remote]
LocallyInstalled
[Res|S]etDefault[Constraint|Version]
, manageconstraint
andversion
files in<rootPath>/<tool>/
Uninstall[Multiple]
Happy hacking !