executil

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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) RunContext added in v0.3.0

func (r *Runner) RunContext(parent context.Context, command string) Result

RunContext is Run that also stops the command (and its process group) when parent is cancelled.

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