Add AST analysis tools and go run/test execution tools

This commit is contained in:
Ian Gulliver
2025-06-27 22:54:45 -07:00
parent 9e94d0693b
commit ee04ab585a
18 changed files with 3796 additions and 5 deletions

25
tool_go_common.go Normal file
View File

@@ -0,0 +1,25 @@
package main
import (
"bytes"
"os/exec"
)
// runCommand executes a command and returns stdout, stderr, exit code, and error
func runCommand(cmd *exec.Cmd) (stdout, stderr string, exitCode int, err error) {
var stdoutBuf, stderrBuf bytes.Buffer
cmd.Stdout = &stdoutBuf
cmd.Stderr = &stderrBuf
err = cmd.Run()
exitCode = 0
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
exitCode = exitErr.ExitCode()
err = nil // Don't treat non-zero exit as error for go commands
}
}
return stdoutBuf.String(), stderrBuf.String(), exitCode, err
}