1 Output Functions
Virgil edited this page 2026-02-23 04:54:00 +00:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Output Functions

All output functions support glyph shortcodes (:check:, :cross:, :warn:, :info:) which are auto-converted to Unicode symbols.

Styled Output

cli.Success("All tests passed")     // ✓ All tests passed (green)
cli.Successf("Built %d files", n)   // ✓ Built 5 files (green)
cli.Error("Connection refused")     // ✗ Connection refused (red, stderr)
cli.Errorf("Port %d in use", port)  // ✗ Port 8080 in use (red, stderr)
cli.Warn("Deprecated flag used")    // ⚠ Deprecated flag used (amber, stderr)
cli.Warnf("Skipping %s", name)     // ⚠ Skipping foo (amber, stderr)
cli.Info("Using default config")    //  Using default config (blue)
cli.Infof("Found %d items", n)     //  Found 42 items (blue)
cli.Dim("Optional detail")         // Optional detail (gray)

Plain Output

cli.Println("Hello %s", name)      // fmt.Sprintf + glyph conversion + newline
cli.Print("Loading...")             // No newline
cli.Text("raw", "text")            // Like fmt.Println but with glyphs
cli.Blank()                         // Empty line
cli.Echo("key.label", args...)     // i18n.T translation + newline

Structured Output

cli.Label("version", "1.2.0")     // Version: 1.2.0 (styled key)
cli.Task("php", "Running tests")  // [php] Running tests
cli.Section("audit")               // ── AUDIT ──
cli.Hint("fix", "go mod tidy")    //   fix: go mod tidy
cli.Result(passed, "Tests passed") // ✓ or ✗ based on bool

Progress

for i, item := range items {
    cli.Progress("check", i+1, len(items), item.Name) // Overwrites line
}
cli.ProgressDone() // Clears progress line

Severity

cli.Severity("critical", "SQL injection found")  // [critical] red+bold
cli.Severity("high", "XSS vulnerability")        // [high] orange+bold
cli.Severity("medium", "Missing CSRF token")     // [medium] amber
cli.Severity("low", "Debug mode enabled")         // [low] gray

Error Wrapping for Output

cli.ErrorWrap(err, "load config")                // ✗ load config: <error>
cli.ErrorWrapVerb(err, "load", "config")         // ✗ Failed to load config: <error>
cli.ErrorWrapAction(err, "connect")              // ✗ Failed to connect: <error>