external
External process runner — exec.Command wrapper with timeout, output capture, error handling
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
result, err := external.Run(ctx, external.Command{
Name: "go",
Args: []string{"build", "-o", "bin/sbx", "./cmd/sbx"},
Dir: "/workspace/shredbx/projects/sbx/packages/core/go",
},
external.WithTimeout(60*time.Second),
external.WithEnv(map[string]string{"CGO_ENABLED": "0"}),
)
if err != nil {
// Typed error classification
var exitErr *external.ExitError
if errors.As(err, &exitErr) {
log.Printf("exit %d: %s", exitErr.Code, result.Stderr)
}
return err
}
log.Printf("built in %s", result.Duration)About
Provides a structured wrapper around os/exec for running external processes. Captures stdout/stderr separately, enforces timeouts, injects environment variables, and classifies exit codes into typed errors.
Public API
| Name | Kind | Signature |
|---|---|---|
| Run | func | func Run(ctx context.Context, cmd Command) (*Result, error) |
| Command | type | type Command struct |
| Result | type | type Result struct |
| WithTimeout | func | func WithTimeout(d time.Duration) Option |
| WithEnv | func | func WithEnv(env map[string]string) Option |
Dependencies
Imported By (7)
Git CLI wrapper — branch operations, commit, status, diff with structured output
Git worktree manager — create, list, remove worktrees with Docker integration
1Password vault adapter — credential retrieval, caching, op:// URI resolution
Build orchestrator — Go/Node/Docker build commands with progress reporting
Database migration runner — up/down/status with versioned SQL files
Image processing pipeline — resize, optimize, format conversion via sips/ImageMagick
PDF generation — HTML-to-PDF rendering with template support
Related Packages
Git CLI wrapper — branch operations, commit, status, diff with structured output
1Password vault adapter — credential retrieval, caching, op:// URI resolution
Build orchestrator — Go/Node/Docker build commands with progress reporting