MCPcopy Index your code
hub / github.com/devspace-sh/devspace / ExecuteCommand

Function ExecuteCommand

cmd/run.go:298–334  ·  view source on GitHub ↗

ExecuteCommand executes a command from the config

(ctx context.Context, cmd *latest.CommandConfig, variables map[string]interface{}, args []string, dir string, stdout io.Writer, stderr io.Writer, stdin io.Reader)

Source from the content-addressed store, hash-verified

296
297// ExecuteCommand executes a command from the config
298func ExecuteCommand(ctx context.Context, cmd *latest.CommandConfig, variables map[string]interface{}, args []string, dir string, stdout io.Writer, stderr io.Writer, stdin io.Reader) error {
299 shellCommand := strings.TrimSpace(cmd.Command)
300 shellArgs := cmd.Args
301 appendArgs := cmd.AppendArgs
302
303 extraEnv := map[string]string{}
304 for k, v := range variables {
305 extraEnv[k] = fmt.Sprintf("%v", v)
306 }
307 if shellArgs == nil {
308 if appendArgs {
309 // Append args to shell command
310 for _, arg := range args {
311 arg = strings.ReplaceAll(arg, "'", "'\"'\"'")
312
313 shellCommand += " '" + arg + "'"
314 }
315 }
316
317 // execute the command in a shell
318 err := engine.ExecuteSimpleShellCommand(ctx, dir, env.NewVariableEnvProvider(expand.ListEnviron(os.Environ()...), extraEnv), stdout, stderr, stdin, shellCommand, args...)
319 if err != nil {
320 if status, ok := interp.IsExitStatus(err); ok {
321 return &exit.ReturnCodeError{
322 ExitCode: int(status),
323 }
324 }
325
326 return errors.Wrap(err, "execute command")
327 }
328
329 return nil
330 }
331
332 shellArgs = append(shellArgs, args...)
333 return command.Command(ctx, dir, env.NewVariableEnvProvider(expand.ListEnviron(os.Environ()...), extraEnv), stdout, stderr, stdin, shellCommand, shellArgs...)
334}
335
336// RunCommandCmd holds the cmd flags of a run command
337type RunCommandCmd struct {

Callers 1

executeCommandWithAfterFunction · 0.85

Calls 3

NewVariableEnvProviderFunction · 0.92
EnvironMethod · 0.65

Tested by

no test coverage detected