MCPcopy
hub / github.com/wavetermdev/waveterm / UpdateCmdEnv

Function UpdateCmdEnv

pkg/util/shellutil/shellutil.go:234–259  ·  view source on GitHub ↗
(cmd *exec.Cmd, envVars map[string]string)

Source from the content-addressed store, hash-verified

232}
233
234func UpdateCmdEnv(cmd *exec.Cmd, envVars map[string]string) {
235 if len(envVars) == 0 {
236 return
237 }
238 found := make(map[string]bool)
239 var newEnv []string
240 for _, envStr := range cmd.Env {
241 envKey := GetEnvStrKey(envStr)
242 newEnvVal, ok := envVars[envKey]
243 if ok {
244 found[envKey] = true
245 if newEnvVal != "" {
246 newEnv = append(newEnv, envKey+"="+newEnvVal)
247 }
248 } else {
249 newEnv = append(newEnv, envStr)
250 }
251 }
252 for envKey, envVal := range envVars {
253 if found[envKey] {
254 continue
255 }
256 newEnv = append(newEnv, envKey+"="+envVal)
257 }
258 cmd.Env = newEnv
259}
260
261func GetEnvStrKey(envStr string) string {
262 eqIdx := strings.Index(envStr, "=")

Callers 2

StartLocalShellProcFunction · 0.92
RunSimpleCmdInPtyFunction · 0.92

Calls 1

GetEnvStrKeyFunction · 0.85

Tested by

no test coverage detected