executil

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 120 * time.Second

DefaultTimeout is the maximum wall-clock time a single command may run.

View Source
const MaxOutputBytes = 1 << 20 // 1 MiB

MaxOutputBytes caps captured stdout/stderr per command.

Variables

This section is empty.

Functions

func Command

func Command(name string, args ...string) *exec.Cmd

Command wraps exec.Command for internal use where arguments are built programmatically from trusted sources (config values, constants). Centralises the gosec G204 suppression to a single location.

func CommandContext

func CommandContext(ctx context.Context, name string, args ...string) *exec.Cmd

CommandContext wraps exec.CommandContext for internal use where arguments are built programmatically from trusted sources.

func Sanitize

func Sanitize(command string) error

Sanitize rejects commands that are empty, too long, contain embedded newlines, or non-printable control characters.

Types

type Result

type Result struct {
	Command  string `json:"command"`
	ExitCode int    `json:"exit_code"`
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
}

Result holds the outcome of a single shell command.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner executes shell commands scoped to a specific project root directory. Commands are always run with sh -c inside the configured root.

func NewRunner

func NewRunner(root string) *Runner

NewRunner creates a command runner bound to the given project root.

func (*Runner) Run

func (r *Runner) Run(command string) Result

Run executes a shell command in the project root directory. The command is validated before execution: it must not be empty, contain embedded newlines, control characters, or exceed the length limit. Commands are killed after the configured timeout (default 120s).

func (*Runner) RunUnchecked

func (r *Runner) RunUnchecked(command string) Result

RunUnchecked executes a command without sanitization. Use only for known-safe internal commands (e.g. go mod init with a validated path).

func (*Runner) WithTimeout

func (r *Runner) WithTimeout(d time.Duration) *Runner

WithTimeout returns a copy of the runner with a custom timeout.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL