output

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package output handles formatted output for the CLI.

This package provides utilities for:

  • Structured field output (label: value format)
  • Unified diff generation with color highlighting
  • User feedback messages (Warning, Hint, Error) with TTY-aware coloring

Colors are automatically disabled when output is not a TTY, ensuring clean output when piped or redirected.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(w io.Writer, oldName, newName, oldContent, newContent string) string

Diff generates a unified diff between two strings, colored for the terminal it will be printed to. Pass the same writer the result is written to so the diff's color tracks that destination's TTY-ness (#341).

func DiffRaw

func DiffRaw(oldName, newName, oldContent, newContent string) string

DiffRaw generates a unified diff between two strings without colors.

func Error

func Error(w io.Writer, format string, args ...any)

Error prints an error message in red. Used for user-facing error messages that are not Go errors. For Go errors, use the standard error return pattern instead.

func Failed

func Failed(w io.Writer, name string, err error)

Failed prints a per-item failure message with a red "Failed" prefix, appending the error that caused it. Example: "Failed /app/config: error message".

func Hint

func Hint(w io.Writer, format string, args ...any)

Hint prints a hint message in cyan. Used to provide helpful suggestions to the user, typically following a warning. Example: "Hint: To compare with previous version, use: suve param diff /param~1".

func Indent

func Indent(s, prefix string) string

Indent adds a prefix to each line of the input string.

func Info

func Info(w io.Writer, format string, args ...any)

Info prints an informational message in cyan with no prefix. Used for status updates, progress messages, and neutral information. Example: "No changes staged.", "Applied 3 staged changes".

func Print added in v0.7.0

func Print(w io.Writer, msg string)

Print writes a message to the writer without a newline.

func Printf added in v0.7.0

func Printf(w io.Writer, format string, args ...any)

Printf writes a formatted message to the writer.

func Println added in v0.7.0

func Println(w io.Writer, msg string)

Println writes a message to the writer with a newline.

func Success

func Success(w io.Writer, format string, args ...any)

Success prints a success message with a green checkmark prefix. Used to confirm a completed action. Example: "✓ Created parameter /app/config".

func Warn added in v0.7.0

func Warn(w io.Writer, format string, args ...any)

Warn prints a warning message with a yellow "!" prefix. Used for per-item caveats within a larger operation. Example: "! Skipped /app/config (same as AWS)".

func Warning

func Warning(w io.Writer, format string, args ...any)

Warning prints a warning message in yellow. Used to alert users about non-critical issues that don't prevent command execution. Example: "Warning: comparing identical versions".

func WriteJSON added in v0.8.0

func WriteJSON(w io.Writer, v any) error

WriteJSON encodes v as indented JSON (two-space indent) followed by a trailing newline, writing the result to w. It is the shared implementation for the CLI's --output=json modes.

Types

type Format

type Format string

Format represents the output format.

const (
	// FormatText is the default human-readable text format.
	FormatText Format = "text"
	// FormatJSON outputs structured JSON.
	FormatJSON Format = "json"
)

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat parses an --output value into a Format. An empty value or "text" is FormatText and "json" is FormatJSON; any other value is a usage error so a typo like "jsonn" fails loudly instead of silently printing text.

type Writer

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

Writer provides formatted output methods.

func New

func New(w io.Writer) *Writer

New creates a new output writer.

func (*Writer) Field

func (o *Writer) Field(label, value string)

Field prints a labeled field.

func (*Writer) Separator

func (o *Writer) Separator()

Separator prints a separator line.

func (*Writer) Value

func (o *Writer) Value(value string)

Value prints a value with proper indentation.

Jump to

Keyboard shortcuts

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