output

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 5 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(oldName, newName, oldContent, newContent string) string

Diff generates a unified diff between two strings with ANSI colors.

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 failure message in red. 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. Used for status updates, progress messages, and neutral information. Example: "No changes staged.", "Agent started".

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 green checkmark. 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 yellow "!" prefix. 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".

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

ParseFormat parses a format string and returns the Format. Returns FormatText for empty string or invalid values.

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