Documentation
¶
Index ¶
- Variables
- func HumanizeTestName(testName string) string
- type Console
- func (c *Console) GetBlueFgColor() string
- func (c *Console) GetBorderChars() (topCorner, bottomCorner, headerChar, verticalChar string)
- func (c *Console) GetColor(colorKey string) string
- func (c *Console) GetErrorColor() string
- func (c *Console) GetGreenFgColor() string
- func (c *Console) GetHeaderWidth() int
- func (c *Console) GetIcon(iconKey string) string
- func (c *Console) GetMutedColor() string
- func (c *Console) GetSuccessColor() string
- func (c *Console) GetWarningColor() string
- func (c *Console) PrintH1Header(name string)
- func (c *Console) PrintSectionFooter()
- func (c *Console) PrintSectionHeader(name string)
- func (c *Console) PrintSectionLine(line string)
- func (c *Console) ResetColor() string
- func (c *Console) Run(label, command string, args ...string) (*TaskResult, error)
- func (c *Console) RunSimple(command string, args ...string) error
- type ConsoleConfig
- type CoverageThreshold
- type ExitCodeError
- type Line
- type ProfileData
- type Profiler
- type TaskResult
- type TestPackageResult
- type TestRenderer
- func (r *TestRenderer) GetConfig() TestTableConfig
- func (r *TestRenderer) RenderGroupFooter()
- func (r *TestRenderer) RenderGroupHeader(dirName string)
- func (r *TestRenderer) RenderPackageLine(pkg TestPackageResult)
- func (r *TestRenderer) RenderTableHeader()
- func (r *TestRenderer) SetConfig(config TestTableConfig)
- type TestResult
- type TestTableConfig
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 ¶
func HumanizeTestName ¶ added in v0.2.0
HumanizeTestName converts Go test names to human-friendly format. Test<Component>_<Behavior>_When_<Condition> -> "Component: Behavior - When Condition"
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) GetBlueFgColor ¶ added in v0.2.0
GetBlueFgColor returns the light blue color code from the theme.
func (*Console) GetBorderChars ¶ added in v0.2.0
GetBorderChars returns the border characters from the theme.
func (*Console) GetErrorColor ¶ added in v0.2.0
GetErrorColor returns the Error color code from the theme.
func (*Console) GetGreenFgColor ¶ added in v0.2.0
GetGreenFgColor returns the light green color code from the theme.
func (*Console) GetHeaderWidth ¶ added in v0.2.0
GetHeaderWidth returns the header width from the theme.
func (*Console) GetMutedColor ¶ added in v0.2.0
GetMutedColor returns the Muted color code from the theme.
func (*Console) GetSuccessColor ¶ added in v0.2.0
GetSuccessColor returns the Success color code from the theme.
func (*Console) GetWarningColor ¶ added in v0.2.0
GetWarningColor returns the Warning color code from the theme.
func (*Console) PrintH1Header ¶ added in v0.2.0
PrintH1Header prints a major headline (H1) using the console's theme.
func (*Console) PrintSectionFooter ¶ added in v0.2.0
func (c *Console) PrintSectionFooter()
PrintSectionFooter closes the section box with a bottom border.
func (*Console) PrintSectionHeader ¶ added in v0.2.0
PrintSectionHeader prints a section header and starts a section box.
func (*Console) PrintSectionLine ¶ added in v0.2.0
PrintSectionLine prints a line of section content with side borders.
func (*Console) ResetColor ¶ added in v0.2.0
ResetColor returns the reset color code from the theme.
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 CoverageThreshold ¶ added in v0.2.0
CoverageThreshold defines a coverage range and its associated color.
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.
type TaskResult ¶
type TaskResult struct {
Label string
Intent string
Status string
Duration time.Duration
ExitCode int
Lines []Line
Err error
}
func (*TaskResult) ToJSON ¶
func (r *TaskResult) ToJSON() ([]byte, error)
ToJSON converts TaskResult to JSON format for structured output.
type TestPackageResult ¶ added in v0.2.0
type TestPackageResult struct {
Name string
Passed int
Failed int
Skipped int
Duration time.Duration
Coverage float64
FailedTests []string
AllTests []TestResult // All tests with their status (when ShowAllTests is enabled)
}
TestPackageResult represents the results for a single test package.
type TestRenderer ¶ added in v0.2.0
type TestRenderer struct {
// contains filtered or unexported fields
}
TestRenderer renders test results using the console's theme.
func NewTestRenderer ¶ added in v0.2.0
func NewTestRenderer(console *Console, writer io.Writer) *TestRenderer
NewTestRenderer creates a new test renderer with the given console and writer.
func (*TestRenderer) GetConfig ¶ added in v0.2.0
func (r *TestRenderer) GetConfig() TestTableConfig
GetConfig returns the current test table configuration.
func (*TestRenderer) RenderGroupFooter ¶ added in v0.2.0
func (r *TestRenderer) RenderGroupFooter()
RenderGroupFooter renders the bottom border of the group box.
func (*TestRenderer) RenderGroupHeader ¶ added in v0.2.0
func (r *TestRenderer) RenderGroupHeader(dirName string)
RenderGroupHeader renders the directory group header and starts a box.
func (*TestRenderer) RenderPackageLine ¶ added in v0.2.0
func (r *TestRenderer) RenderPackageLine(pkg TestPackageResult)
RenderPackageLine renders a single package test result line.
func (*TestRenderer) RenderTableHeader ¶ added in v0.2.0
func (r *TestRenderer) RenderTableHeader()
RenderTableHeader renders the table header with column labels in a complete box.
func (*TestRenderer) SetConfig ¶ added in v0.2.0
func (r *TestRenderer) SetConfig(config TestTableConfig)
SetConfig updates the test table configuration.
type TestResult ¶ added in v0.2.0
TestResult represents a single test with its status.
type TestTableConfig ¶ added in v0.2.0
type TestTableConfig struct {
// SparkbarFilled is the character used for filled portions of the sparkbar
SparkbarFilled string
// SparkbarEmpty is the character used for empty portions of the sparkbar
SparkbarEmpty string
// SparkbarLength is the number of characters in the sparkbar
SparkbarLength int
// CoverageThresholds defines the coverage ranges for color coding
// Format: [[0, 39, "Error"], [40, 69, "Warning"], [70, 100, "Success"]]
CoverageThresholds []CoverageThreshold
// ShowPercentage controls whether to show percentage after sparkbar
ShowPercentage bool
// UseTreeChars controls whether to use tree characters (├─, └─)
UseTreeChars bool
// NoTestIcon is the icon to use for packages with no tests
NoTestIcon string
// NoTestColor is the color key for packages with no tests
NoTestColor string
// ShowAllTests controls whether to show all tests (including passed) with their status
ShowAllTests bool
}
TestTableConfig configures how test results are rendered.