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

Function execCommand

pkg/devspace/config/loader/variable/command_variable.go:54–81  ·  view source on GitHub ↗
(ctx context.Context, varName string, definition *latest.Variable, cmd string, args []string, dir string)

Source from the content-addressed store, hash-verified

52}
53
54func execCommand(ctx context.Context, varName string, definition *latest.Variable, cmd string, args []string, dir string) (interface{}, error) {
55 writer := &bytes.Buffer{}
56 stdErrWriter := &bytes.Buffer{}
57 var err error
58 envVars := []string{}
59 envVars = append(envVars, expression.DevSpaceSkipPreloadEnv+"=true")
60 envVars = append(envVars, os.Environ()...)
61 if args == nil {
62 err = engine.ExecuteSimpleShellCommand(ctx, dir, expand.ListEnviron(envVars...), writer, stdErrWriter, nil, cmd, os.Args[1:]...)
63 } else {
64 err = command.Command(ctx, dir, expand.ListEnviron(envVars...), writer, stdErrWriter, nil, cmd, args...)
65 }
66 if err != nil {
67 errMsg := "fill variable " + varName + " with command '" + cmd + "': " + err.Error()
68 if len(writer.Bytes()) > 0 {
69 errMsg = errMsg + "\n\nstdout: \n" + writer.String()
70 }
71 if len(stdErrWriter.Bytes()) > 0 {
72 errMsg = errMsg + "\n\nstderr: \n" + stdErrWriter.String()
73 }
74
75 return "", errors.New(errMsg)
76 } else if writer.String() == "" {
77 return definition.Default, nil
78 }
79
80 return convertStringValue(strings.TrimSpace(writer.String())), nil
81}

Callers 1

variableFromCommandFunction · 0.85

Calls 5

StringMethod · 0.95
convertStringValueFunction · 0.85
EnvironMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected