outfmt

package
v1.9.6 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertTime added in v0.6.0

func ConvertTime(utcStr string, loc *time.Location) string

ConvertTime parses a UTC time string and converts it to the given location. For date-only inputs, returns "2006-01-02". For datetime inputs, returns "2006-01-02 15:04". Returns the original string unchanged if loc is nil or parsing fails.

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 {
	UntrustedNotice string      `json:"untrustedNotice,omitempty"`
	Results         interface{} `json:"results"`
	Count           int         `json:"count"`
	NextLink        string      `json:"nextLink,omitempty"`
	// Delta-sync continuation (set only by delta/changes commands). DeltaToken is
	// the opaque cursor to pass back next time; DeltaComplete reports whether the
	// caller is caught up (token is a deltaLink) or more pages remain now.
	DeltaToken    string `json:"deltaToken,omitempty"`
	DeltaComplete *bool  `json:"deltaComplete,omitempty"`
	Timezone      string `json:"timezone,omitempty"`
}

Envelope is the JSON output wrapper. UntrustedNotice is emitted first (and only when --wrap-untrusted is set) so a consuming LLM reads the security directive before the wrapped, externally-controlled results.

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
	Timezone      string // IANA timezone name for JSON envelope metadata
	WrapUntrusted bool   // wrap externally-controlled free-text fields in JSON output
	Concise       bool   // drop large free-text fields (bodies, previews, attendees) from JSON output
}

Printer handles output formatting

func NewPrinter

func NewPrinter(jsonFlag, plainFlag, resultsOnly bool, selectFields, timezone string, wrapUntrusted, concise bool) *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) PrintDelta added in v1.9.6

func (p *Printer) PrintDelta(headers []string, rows [][]string, jsonData interface{}, count int, token string, complete bool) error

PrintDelta renders a delta-sync page: in JSON mode it emits the envelope with the continuation token and completeness (results still wrapped/concised like PrintJSON); in table/plain mode it prints the rows followed by the token and complete flag so a human/script can resume.

func (*Printer) PrintJSON

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

PrintJSON outputs data as JSON with envelope. When WrapUntrusted is set, fields tagged `untrusted:"true"` are wrapped with markers so an LLM/agent consumer can distinguish externally-controlled text from trusted output.

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