-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tenvlib package to easily use tenv as a library (#240)
* add tenvlib package (use context.Context) * add TENV_AS_LIB.md * add examples Signed-off-by: Denis Vaumoron <dvaumoron@gmail.com>
- Loading branch information
Showing
24 changed files
with
712 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# How to use tenv as a library | ||
|
||
## Get started | ||
|
||
### Prerequisites | ||
|
||
**tenv** requires [Go](https://go.dev) version [1.21](https://go.dev/doc/devel/release#go1.21.0) or above. | ||
|
||
### Getting tenv module | ||
|
||
`tenvlib` package is available since tenv v3.2 | ||
|
||
```console | ||
go get -u github.com/tofuutils/tenv/v3@latest | ||
``` | ||
|
||
### Basic example | ||
|
||
```go | ||
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) | ||
} | ||
} | ||
``` | ||
|
||
## Documentation | ||
|
||
See the [API documentation on go.dev](https://pkg.go.dev/github.com/tofuutils/tenv/v3/versionmanager/tenvlib) and [examples](https://github.com/tofuutils/tenv/tree/main/versionmanager/tenvlib/examples). | ||
|
||
### Overview | ||
|
||
Available Tenv struct creation options : | ||
|
||
- `AddTool(toolName string, builderFunc builder.BuilderFunc)`, extend `tenvlib` to support other tool use cases. | ||
- `AutoInstall`, shortcut to force auto install feature enabling in `config.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 default `Config` (one from a `InitConfigFromEnv` or `DefaultConfig` call depending on `IgnoreEnv` usage). | ||
- `WithDisplayer(displayer loghelper.Displayer)`, replace default `Displayer` with a custom to handle `tenvlib` output (standard and log). | ||
- `WithHCLParser(hclParser *hclparse.Parser)`, use passed `Parser` 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]`, manage `constraint` and `version` files in `<rootPath>/<tool>/` | ||
- `Uninstall[Multiple]` | ||
|
||
Happy hacking ! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.