outfmt

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sanitize

func Sanitize(s string) string

Sanitize removes control characters from a string, replacing newlines with spaces (safe for single-line table cells). Use SanitizeMultiline for free-text body output where newlines should be preserved.

func SanitizeMultiline

func SanitizeMultiline(s string) string

SanitizeMultiline removes control characters but preserves newlines, suitable for multi-line body text output.

func Truncate

func Truncate(s string, maxRunes int) string

Truncate truncates a string to maxRunes runes, appending "..." if truncated. Unlike byte-level slicing, this is safe for multi-byte UTF-8 characters.

Types

type Envelope

type Envelope struct {
	Results  interface{} `json:"results"`
	Count    int         `json:"count"`
	NextLink string      `json:"nextLink,omitempty"`
}

Envelope is the JSON output wrapper

type Format

type Format int
const (
	FormatTable Format = iota
	FormatJSON
	FormatPlain // TSV
)

type Printer

type Printer struct {
	Format      Format
	Writer      io.Writer
	Select      string // comma-separated field names
	ResultsOnly bool
}

Printer handles output formatting

func NewPrinter

func NewPrinter(jsonFlag, plainFlag, resultsOnly bool, selectFields string) *Printer

NewPrinter creates a printer from flags

func (*Printer) Print

func (p *Printer) Print(headers []string, rows [][]string, jsonData interface{}, count int, nextLink string) error

Print dispatches to the appropriate format

func (*Printer) PrintJSON

func (p *Printer) PrintJSON(results interface{}, count int, nextLink string) error

PrintJSON outputs data as JSON with envelope

func (*Printer) PrintPlain

func (p *Printer) PrintPlain(headers []string, rows [][]string) error

PrintPlain outputs data as TSV (no headers)

func (*Printer) PrintTable

func (p *Printer) PrintTable(headers []string, rows [][]string) error

PrintTable outputs data as an aligned table

Jump to

Keyboard shortcuts

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