reporter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 5 Imported by: 5

Documentation

Overview

Package reporter provides a progress reporting interface with text, JSON Lines, and no-op implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventType

type EventType string

EventType represents the type of progress event.

const (
	EventTypeStep     EventType = "step"
	EventTypeProgress EventType = "progress"
	EventTypeMessage  EventType = "message"
	EventTypeWarning  EventType = "warning"
	EventTypeError    EventType = "error"
	EventTypeComplete EventType = "complete"
)

type JSONReporter

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

JSONReporter writes JSON Lines (one ProgressEvent per line) to an io.Writer. All writes are serialized with a mutex for thread safety.

func NewJSONReporter

func NewJSONReporter(w io.Writer) *JSONReporter

NewJSONReporter returns a JSONReporter that writes to w.

func (*JSONReporter) Complete

func (r *JSONReporter) Complete(message string, details any)

func (*JSONReporter) Error

func (r *JSONReporter) Error(err error, message string)

func (*JSONReporter) IsJSON

func (r *JSONReporter) IsJSON() bool

func (*JSONReporter) Message

func (r *JSONReporter) Message(format string, args ...any)

func (*JSONReporter) MessagePlain

func (r *JSONReporter) MessagePlain(format string, args ...any)

func (*JSONReporter) Progress

func (r *JSONReporter) Progress(percent int, message string)

func (*JSONReporter) Step

func (r *JSONReporter) Step(step, total int, name string)

func (*JSONReporter) Warning

func (r *JSONReporter) Warning(format string, args ...any)

type NoopReporter

type NoopReporter struct{}

NoopReporter silently discards all output. Useful for tests and contexts where no progress reporting is needed.

func (NoopReporter) Complete

func (NoopReporter) Complete(string, any)

func (NoopReporter) Error

func (NoopReporter) Error(error, string)

func (NoopReporter) IsJSON

func (NoopReporter) IsJSON() bool

func (NoopReporter) Message

func (NoopReporter) Message(string, ...any)

func (NoopReporter) MessagePlain

func (NoopReporter) MessagePlain(string, ...any)

func (NoopReporter) Progress

func (NoopReporter) Progress(int, string)

func (NoopReporter) Step

func (NoopReporter) Step(int, int, string)

func (NoopReporter) Warning

func (NoopReporter) Warning(string, ...any)

type ProgressEvent

type ProgressEvent struct {
	Type       EventType `json:"type"`
	Timestamp  string    `json:"timestamp"`
	Step       int       `json:"step,omitzero"`
	TotalSteps int       `json:"total_steps,omitzero"`
	StepName   string    `json:"step_name,omitempty"`
	Message    string    `json:"message,omitempty"`
	Percent    int       `json:"percent,omitzero"`
	Details    any       `json:"details,omitempty"`
}

ProgressEvent represents a single line of JSON Lines output for streaming progress.

type Reporter

type Reporter interface {
	Step(step, total int, name string)
	Progress(percent int, message string)
	Message(format string, args ...any)
	MessagePlain(format string, args ...any)
	Warning(format string, args ...any)
	Error(err error, message string)
	Complete(message string, details any)
	IsJSON() bool
}

Reporter is the interface for reporting progress and messages. It has three implementations:

  • TextReporter: human-readable text output
  • JSONReporter: machine-readable JSON Lines output
  • NoopReporter: silently discards all output

type TextReporter

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

TextReporter writes human-readable progress text to an io.Writer.

func NewTextReporter

func NewTextReporter(w io.Writer) *TextReporter

NewTextReporter returns a TextReporter that writes to w.

func (*TextReporter) Complete

func (r *TextReporter) Complete(message string, _ any)

func (*TextReporter) Error

func (r *TextReporter) Error(err error, message string)

func (*TextReporter) IsJSON

func (r *TextReporter) IsJSON() bool

func (*TextReporter) Message

func (r *TextReporter) Message(format string, args ...any)

func (*TextReporter) MessagePlain

func (r *TextReporter) MessagePlain(format string, args ...any)

func (*TextReporter) Progress

func (r *TextReporter) Progress(_ int, message string)

func (*TextReporter) Step

func (r *TextReporter) Step(step, total int, name string)

func (*TextReporter) Warning

func (r *TextReporter) Warning(format string, args ...any)

Jump to

Keyboard shortcuts

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