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 ¶
- func Diff(w io.Writer, oldName, newName, oldContent, newContent string) string
- func DiffRaw(oldName, newName, oldContent, newContent string) string
- func Error(w io.Writer, format string, args ...any)
- func Failed(w io.Writer, name string, err error)
- func Hint(w io.Writer, format string, args ...any)
- func Indent(s, prefix string) string
- func Info(w io.Writer, format string, args ...any)
- func Print(w io.Writer, msg string)
- func Printf(w io.Writer, format string, args ...any)
- func Println(w io.Writer, msg string)
- func Success(w io.Writer, format string, args ...any)
- func Warn(w io.Writer, format string, args ...any)
- func Warning(w io.Writer, format string, args ...any)
- func WriteJSON(w io.Writer, v any) error
- type Format
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Diff ¶
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 Error ¶
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 ¶
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 ¶
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 Info ¶
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 Success ¶
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
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)".
Types ¶
type Format ¶
type Format string
Format represents the output format.
func ParseFormat ¶
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.