Documentation
¶
Overview ¶
Package output selects between human-readable and JSON output modes and enforces the stdout/stderr split required by the UX contract.
Index ¶
- func ConflictQuietVerbose(quiet, verbose bool) error
- type ErrorEnvelope
- type ErrorJSON
- type Mode
- type Verbosity
- type Writer
- func (w *Writer) ApplyFlags(jsonMode, quiet, verbose, noColor bool) error
- func (w *Writer) Debugf(format string, args ...any)
- func (w *Writer) ExitTrailer(code int)
- func (w *Writer) Infof(format string, args ...any)
- func (w *Writer) Primary(v any) error
- func (w *Writer) RenderError(err error)
- func (w *Writer) Warnf(format string, args ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConflictQuietVerbose ¶
ConflictQuietVerbose returns a USAGE CLIError if both quiet and verbose are set — enforced by root.go before any I/O.
Types ¶
type ErrorEnvelope ¶
ErrorEnvelope is the top-level JSON produced on failure. Callers may wrap it with command-specific fields before emitting.
type ErrorJSON ¶
ErrorJSON is the wire shape used inside JSON primary output when an error is returned instead of a success record.
type Verbosity ¶
type Verbosity int
Verbosity controls stderr diagnostic chatter.
const ( // VerbosityNormal is the default: info+warn on stderr. VerbosityNormal Verbosity = iota // VerbosityQuiet suppresses progress/info on stderr. Warnings still emitted. VerbosityQuiet // VerbosityVerbose emits debug-level diagnostics on stderr and // includes an "exit=<code> reason=<name>" trailer. VerbosityVerbose )
type Writer ¶
type Writer struct {
// Stdout carries primary data only. Tests may wire a buffer here.
Stdout io.Writer
// Stderr carries diagnostics, progress, and prompts.
Stderr io.Writer
// Mode selects human vs JSON primary output.
Mode Mode
// Verbosity gates the stderr stream.
Verbosity Verbosity
// NoColor disables ANSI formatting (currently informational; color
// is not yet enabled, so this bit is reserved for future use).
NoColor bool
}
Writer is the single object every command writes through. It enforces the stdout/stderr split (Constitution III) and handles JSON vs human selection (contracts/json-output.md).
func New ¶
func New() *Writer
New returns a Writer wired to os.Stdout/os.Stderr with human output and normal verbosity. Commands typically construct one per invocation and override fields from persistent flags.
func (*Writer) ApplyFlags ¶
ApplyFlags resolves the combined flag state into Writer fields. The NO_COLOR environment variable is honored here rather than in each command.
func (*Writer) ExitTrailer ¶
ExitTrailer emits the verbose exit summary line when verbose is on.
func (*Writer) Primary ¶
Primary writes v to stdout. In human mode, v must implement fmt.Stringer or be a plain string. In JSON mode, v is JSON-marshalled + newline.
func (*Writer) RenderError ¶
RenderError writes the human-readable error tree to stderr and, in JSON mode, writes the ErrorEnvelope to stdout.