MCPcopy Create free account
hub / github.com/diillson/chatcli / executeNonInteractive

Method executeNonInteractive

cli/agent/command_executor.go:136–167  ·  view source on GitHub ↗

executeNonInteractive executa comando capturando saída

(ctx context.Context, shell, shellFlag, command string)

Source from the content-addressed store, hash-verified

134
135// executeNonInteractive executa comando capturando saída
136func (e *CommandExecutor) executeNonInteractive(ctx context.Context, shell, shellFlag, command string) (*ExecutionResult, error) {
137 start := time.Now()
138 result := &ExecutionResult{Command: command}
139
140 cmd := exec.CommandContext(ctx, shell, shellFlag, command) //#nosec G204 G702 -- agent shell command, validated upstream by command_validator + policy_manager
141 var stdout, stderr bytes.Buffer
142 cmd.Stdout = &stdout
143 cmd.Stderr = &stderr
144 cmd.Stdin = os.Stdin
145
146 err := cmd.Run()
147 result.Duration = time.Since(start)
148
149 result.Output = utils.SanitizeSensitiveText(stdout.String())
150 result.Error = utils.SanitizeSensitiveText(stderr.String())
151
152 if err != nil {
153 var exitErr *exec.ExitError
154 if errors.As(err, &exitErr) {
155 if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
156 result.ExitCode = status.ExitStatus()
157 }
158 }
159 }
160
161 e.logger.Debug("Comando não-interativo executado",
162 zap.String("command", command),
163 zap.Int("exit_code", result.ExitCode),
164 zap.Duration("duration", result.Duration))
165
166 return result, err
167}
168
169// executeInteractive executa comando interativo
170func (e *CommandExecutor) executeInteractive(ctx context.Context, shell, shellFlag, command string) (*ExecutionResult, error) {

Callers 1

ExecuteMethod · 0.95

Implementers 2

MockCommandExecutorutils/git_utils_test.go
OSCommandExecutorutils/exec_utils.go

Calls 3

SanitizeSensitiveTextFunction · 0.92
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected