Skip to content
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

gexe.Envs Function doesn't work when multiple key/vals are passed as string #64

Open
mdzhigarov opened this issue Jan 13, 2025 · 2 comments

Comments

@mdzhigarov
Copy link

mdzhigarov commented Jan 13, 2025

There is an example in the README of how to use the gexe.Envs function:

func main() {
	for _, arch := range []string{"amd64"} {
		for _, opsys := range []string{"darwin", "linux"} {
			gexe.SetVar("arch", arch).SetVar("os", opsys)
			gexe.SetVar("binpath", fmt.Sprintf("build/%s/%s/mybinary", arch, opsys))
			result := gexe.Envs("CGO_ENABLED=0 GOOS=$os GOARCH=$arch").Run("go build -o $binpath .")
			if result != "" {
				fmt.Printf("Build for %s/%s failed: %s\n", arch, opsys, result)
				os.Exit(1)
			}
			fmt.Printf("Build %s/%s: %s OK\n", arch, opsys, echo.Eval("$binpath"))
		}
	}
}

It looks like the parser doesn't work as expected.
gexe.Envs("CGO_ENABLED=0 GOOS=$os GOARCH=$arch") is not parsed correctly and it looks like the the 3 environment variables are not being passed to the process at all. This can easily be proven by inspecting the vars := e.vars.Envs(variables...) after execution with the debugger.

mdzhigarov pushed a commit to vmware-tanzu/crash-diagnostics that referenced this issue Jan 13, 2025
mdzhigarov pushed a commit to vmware-tanzu/crash-diagnostics that referenced this issue Jan 13, 2025
mdzhigarov added a commit to vmware-tanzu/crash-diagnostics that referenced this issue Jan 13, 2025
* Bumps gexe to 0.4.0

Additional fixes:
- Fixes a bug in ssh.go where the retry logic did not work due to using StartProc instead of RunProc in the backoff callback
- Fixes the ssh key setup on Mac where id_rsa private key was getting created with wrong permissions

* Bumps checkout action version

* Fix how we pass env vars to the ssh agent.

See also vladimirvivien/gexe#64

---------

Co-authored-by: Marin Dzhigarov <[email protected]>
@vladimirvivien
Copy link
Owner

Hi @mdzhigarov the API's behavior changed in v0.4.1 to fix this. Instead of doing multiple declarations in one string, you add each declarations in separate strings as in:

result := gexe.Envs("CGO_ENABLED=0", "GOOS=$os", "GOARCH=$arch").Run("go build -o $binpath .")

See example here - https://github.com/vladimirvivien/gexe/blob/main/examples/build/main.go

I see the README.md needs updating 😞

@mdzhigarov
Copy link
Author

Yep, I realized that but the readme needs a bit of tweaking. Also it'd be good to update the godocs comment inside the functions.go code above Env

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants