Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNonZeroExit = errors.New("command exited with non-zero code")
ErrNonZeroExit is returned when a command completes but exits with a non-zero code. Use errors.Is(err, ErrNonZeroExit) to check for this condition.
Functions ¶
This section is empty.
Types ¶
type Console ¶
type Console struct {
// contains filtered or unexported fields
}
func DefaultConsole ¶
func DefaultConsole() *Console
func NewConsole ¶
func NewConsole(cfg ConsoleConfig) *Console
func (*Console) Run ¶
func (c *Console) Run(label, command string, args ...string) (*TaskResult, error)
Run executes a command and returns the result.
Error semantics:
- Returns (result, nil) when the command runs successfully (exit code 0)
- Returns (result, error) when the command runs but exits non-zero; the error wraps the underlying exec.ExitError
- Returns (result, error) for infrastructure failures (command not found, IO errors, context cancelled)
Note: TaskResult is always non-nil. Even for infrastructure failures, the result contains useful information like duration, label, and any captured internal error messages. Use TaskResult.ExitCode (127 for command not found, 1 for other failures) and TaskResult.Err for failure details.
Use errors.Is(err, exec.ErrNotFound) to check for missing commands.
func (*Console) RunSimple ¶
RunSimple executes a command and returns only an error. This is a convenience wrapper around Run for simple use cases where you only need to know success vs failure.
Returns nil on success (exit code 0). Returns ErrNonZeroExit (wrapped with ExitCodeError) if the command exits with non-zero code. Returns other errors for infrastructure failures.
To check for non-zero exit and extract the code:
if errors.Is(err, ErrNonZeroExit) {
var exitErr mageconsole.ExitCodeError
if errors.As(err, &exitErr) {
fmt.Printf("Exit code: %d\n", exitErr.Code)
}
}
For detailed results including captured output, use Run() instead.
type ConsoleConfig ¶
type ConsoleConfig struct {
ThemeName string
UseBoxes bool
UseBoxesSet bool
InlineProgress bool
InlineSet bool
Monochrome bool
ShowTimer bool
ShowTimerSet bool
ShowOutputMode string
Stream bool
Pattern string // Manual pattern selection hint (e.g., "test-table", "sparkline", "leaderboard")
Debug bool
Profile bool // Enable performance profiling
ProfileOutput string // Profile output destination
MaxBufferSize int64
MaxLineLength int
Design *design.Config
Out io.Writer // Output writer, defaults to os.Stdout
Err io.Writer // Error writer, defaults to os.Stderr
}
type ExitCodeError ¶
type ExitCodeError struct {
Code int
}
ExitCodeError wraps an exit code for programmatic access. Use errors.As(err, &ExitCodeError{}) to extract the exit code from RunSimple errors.
func (ExitCodeError) Error ¶
func (e ExitCodeError) Error() string
type Line ¶
type Line struct {
Content string
Type string // "detail", "error", "warning", "success", "info", "progress"
Timestamp time.Time
}
Line represents a classified line of command output. This is the public-facing type that doesn't leak internal design package types.
type ProfileData ¶
type ProfileData struct {
Stage string `json:"stage"`
Duration time.Duration `json:"duration"`
DurationMs int64 `json:"duration_ms"`
PatternMatches int `json:"pattern_matches,omitempty"`
PatternSuccess int `json:"pattern_success,omitempty"`
BufferSize int64 `json:"buffer_size,omitempty"`
LineCount int `json:"line_count,omitempty"`
MemoryAlloc int64 `json:"memory_alloc,omitempty"`
}
ProfileData tracks performance metrics for each pipeline stage.
type Profiler ¶
type Profiler struct {
// contains filtered or unexported fields
}
Profiler tracks performance metrics throughout command execution.
func NewProfiler ¶
NewProfiler creates a new profiler instance.
func (*Profiler) StartStage ¶
StartStage marks the start of a performance stage.