From 4a0e597fcd168d1d0b9ac03a39b39592c20c1dd7 Mon Sep 17 00:00:00 2001 From: Denis Vaumoron Date: Mon, 28 Oct 2024 19:54:58 +0100 Subject: [PATCH] use TENV_DETACHED_PROXY in lightproxy (#274) Signed-off-by: Denis Vaumoron --- versionmanager/proxy/agnostic.go | 3 ++- versionmanager/proxy/{ => detach}/detached_others.go | 4 ++-- versionmanager/proxy/{ => detach}/detached_windows.go | 4 ++-- versionmanager/proxy/light/light.go | 2 ++ versionmanager/proxy/proxy.go | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) rename versionmanager/proxy/{ => detach}/detached_others.go (94%) rename versionmanager/proxy/{ => detach}/detached_windows.go (94%) diff --git a/versionmanager/proxy/agnostic.go b/versionmanager/proxy/agnostic.go index f508e002..33f761b7 100644 --- a/versionmanager/proxy/agnostic.go +++ b/versionmanager/proxy/agnostic.go @@ -30,6 +30,7 @@ import ( "github.com/tofuutils/tenv/v3/config/cmdconst" cmdproxy "github.com/tofuutils/tenv/v3/pkg/cmdproxy" "github.com/tofuutils/tenv/v3/versionmanager/builder" + detachproxy "github.com/tofuutils/tenv/v3/versionmanager/proxy/detach" ) // Always call os.Exit. @@ -77,7 +78,7 @@ func ExecAgnostic(conf *config.Config, hclParser *hclparse.Parser, cmdArgs []str execPath := ExecPath(installPath, detectedVersion, execName, conf.Displayer) cmd := exec.CommandContext(ctx, execPath, cmdArgs...) - initDetachedBehaviorFromEnv(cmd) + detachproxy.InitBehaviorFromEnv(cmd) cmdproxy.Run(cmd, conf.GithubActions) } diff --git a/versionmanager/proxy/detached_others.go b/versionmanager/proxy/detach/detached_others.go similarity index 94% rename from versionmanager/proxy/detached_others.go rename to versionmanager/proxy/detach/detached_others.go index 48bd060b..c2422dae 100644 --- a/versionmanager/proxy/detached_others.go +++ b/versionmanager/proxy/detach/detached_others.go @@ -18,7 +18,7 @@ * */ -package proxy +package detachproxy import ( "fmt" @@ -28,7 +28,7 @@ import ( configutils "github.com/tofuutils/tenv/v3/config/utils" ) -func initDetachedBehaviorFromEnv(cmd *exec.Cmd) { +func InitBehaviorFromEnv(cmd *exec.Cmd) { detached, err := configutils.GetenvBool(false, "TENV_DETACHED_PROXY") if err != nil { fmt.Println("Failed to read TENV_DETACHED_PROXY environment variable, disable behavior :", err) //nolint diff --git a/versionmanager/proxy/detached_windows.go b/versionmanager/proxy/detach/detached_windows.go similarity index 94% rename from versionmanager/proxy/detached_windows.go rename to versionmanager/proxy/detach/detached_windows.go index 13c623a4..8933d424 100644 --- a/versionmanager/proxy/detached_windows.go +++ b/versionmanager/proxy/detach/detached_windows.go @@ -16,7 +16,7 @@ * */ -package proxy +package detachproxy import ( "fmt" @@ -25,7 +25,7 @@ import ( configutils "github.com/tofuutils/tenv/v3/config/utils" ) -func initDetachedBehaviorFromEnv(_ *exec.Cmd) { +func InitBehaviorFromEnv(_ *exec.Cmd) { switch detached, err := configutils.GetenvBool(false, "TENV_DETACHED_PROXY"); { case err != nil: fmt.Println("TENV_DETACHED_PROXY behavior is always disabled on Windows OS, failed to read environment variable :", err) //nolint diff --git a/versionmanager/proxy/light/light.go b/versionmanager/proxy/light/light.go index 4bbedcdc..75c450cf 100644 --- a/versionmanager/proxy/light/light.go +++ b/versionmanager/proxy/light/light.go @@ -26,6 +26,7 @@ import ( "os/signal" "github.com/tofuutils/tenv/v3/config/cmdconst" + detachproxy "github.com/tofuutils/tenv/v3/versionmanager/proxy/detach" ) func Exec(execName string) { @@ -35,6 +36,7 @@ func Exec(execName string) { // proxy to selected version cmd := exec.Command(cmdconst.TenvName, cmdArgs...) //nolint + detachproxy.InitBehaviorFromEnv(cmd) cmd.Stderr = os.Stderr cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout diff --git a/versionmanager/proxy/proxy.go b/versionmanager/proxy/proxy.go index 98c9bb11..5d55f0d9 100644 --- a/versionmanager/proxy/proxy.go +++ b/versionmanager/proxy/proxy.go @@ -33,6 +33,7 @@ import ( "github.com/tofuutils/tenv/v3/pkg/loghelper" "github.com/tofuutils/tenv/v3/versionmanager/builder" "github.com/tofuutils/tenv/v3/versionmanager/lastuse" + detachproxy "github.com/tofuutils/tenv/v3/versionmanager/proxy/detach" ) const chdirFlagPrefix = "-chdir=" @@ -60,7 +61,7 @@ func Exec(conf *config.Config, builderFunc builder.Func, hclParser *hclparse.Par execPath := ExecPath(installPath, detectedVersion, execName, conf.Displayer) cmd := exec.CommandContext(ctx, execPath, cmdArgs...) - initDetachedBehaviorFromEnv(cmd) + detachproxy.InitBehaviorFromEnv(cmd) cmdproxy.Run(cmd, conf.GithubActions) }