MCPcopy Create free account
hub / github.com/docker/docker-agent / PrependBinDirToEnv

Function PrependBinDirToEnv

pkg/toolinstall/paths.go:40–59  ·  view source on GitHub ↗

PrependBinDirToEnv takes an env slice and ensures the tools bin directory is prepended to the PATH entry. This allows installed tools to find other installed tools (e.g., npx finding node).

(env []string)

Source from the content-addressed store, hash-verified

38// is prepended to the PATH entry. This allows installed tools to find
39// other installed tools (e.g., npx finding node).
40func PrependBinDirToEnv(env []string) []string {
41 binDir := BinDir()
42 result := make([]string, 0, len(env))
43 found := false
44
45 for _, e := range env {
46 if existing, ok := strings.CutPrefix(e, "PATH="); ok {
47 result = append(result, "PATH="+binDir+string(os.PathListSeparator)+existing)
48 found = true
49 } else {
50 result = append(result, e)
51 }
52 }
53
54 if !found {
55 result = append(result, "PATH="+binDir)
56 }
57
58 return result
59}

Callers 5

CreateToolSetFunction · 0.92
CreateToolSetFunction · 0.92

Calls 1

BinDirFunction · 0.85