Skip to content

Commit 97a91cc

Browse files
fix: set correct env vars on recursive calls (#1989)
Co-authored-by: Trevor Brown <[email protected]>
1 parent 3dd0dd3 commit 97a91cc

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ charset = utf-8
88
trim_trailing_whitespace = true
99
insert_final_newline = true
1010

11+
[*.go]
12+
indent_style = tab
13+
1114
[*.py]
1215
indent_size = 4
1316

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ repository
55
.vagrant
66
keyrings
77
/tmp
8+
.idea
89

910
dist/
1011

internal/cli/cli.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,12 @@ func Execute(version string) {
342342
},
343343
}
344344

345-
if err := app.Run(os.Args); err != nil {
345+
err := unsetAsdfReservedEnvVars()
346+
if err != nil {
347+
cli.OsExiter(1)
348+
}
349+
350+
if err = app.Run(os.Args); err != nil {
346351
cli.OsExiter(1)
347352
}
348353
}
@@ -1567,3 +1572,16 @@ func installedStatus(installed bool) string {
15671572
}
15681573
return "missing"
15691574
}
1575+
1576+
func unsetAsdfReservedEnvVars() error {
1577+
// These are environment variables which are passed via env or exec.
1578+
// We strip these out to avoid any potential issues with recursive calls to asdf.
1579+
asdfManagedVars := []string{"ASDF_INSTALL_TYPE", "ASDF_INSTALL_VERSION", "ASDF_INSTALL_PATH"}
1580+
for _, v := range asdfManagedVars {
1581+
err := os.Unsetenv(v)
1582+
if err != nil {
1583+
return err
1584+
}
1585+
}
1586+
return nil
1587+
}

test/plugin_extension_command.bats

+19
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,22 @@ EOF
116116
[ "$status" -eq 0 ]
117117
[ "$output" = "$expected" ]
118118
}
119+
120+
@test "asdf execute plugin default command unsets ASDF_INSTALL_TYPE ASDF_INSTALL_VERSION and ASDF_INSTALL_PATH env variables" {
121+
export ASDF_INSTALL_VERSION=1.2.3
122+
export ASDF_INSTALL_TYPE=version
123+
export ASDF_INSTALL_PATH=/somewhere
124+
125+
plugin_path="$(get_plugin_path dummy)"
126+
127+
# this plugin defines a new `asdf dummy` command
128+
cat <<'EOF' >"$plugin_path/lib/commands/command"
129+
#!/usr/bin/env bash
130+
/usr/bin/env
131+
EOF
132+
chmod +x "$plugin_path/lib/commands/command"
133+
134+
run asdf cmd dummy
135+
[ "$status" -eq 0 ]
136+
[ "0" -eq "$(echo "$output" | grep -c "ASDF_INSTALL_")" ]
137+
}

0 commit comments

Comments
 (0)