formatter

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const APIVersion = 1

APIVersion is the version of the JSON and YAML output schema

Variables

This section is empty.

Functions

func IsTable added in v0.4.0

func IsTable(format string) bool

IsTable reports whether format is the human-readable table format

func WriteEnvelope added in v0.5.0

func WriteEnvelope(format string, w io.Writer, env Envelope) error

WriteEnvelope writes env as JSON or YAML

Types

type AppDetails added in v0.5.0

type AppDetails struct {
	App              domain.App            `json:"app" yaml:"app"`
	SupportedTypes   []domain.DocumentType `json:"supported_types" yaml:"supported_types"`
	DefaultTypes     []domain.DocumentType `json:"default_types" yaml:"default_types"`
	RegisteredCopies []domain.AppCopy      `json:"registered_copies" yaml:"registered_copies"`
}

AppDetails is the data of apps show

type DataFormatter added in v0.5.0

type DataFormatter struct {
	// contains filtered or unexported fields
}

DataFormatter hands each command's data to emit, to be written in the envelope once the command finishes

func NewData added in v0.5.0

func NewData(emit func(any)) *DataFormatter

NewData returns a Formatter that passes data to emit

func (*DataFormatter) FormatAppDetails added in v0.5.0

func (f *DataFormatter) FormatAppDetails(
	app domain.App,
	supportedTypes []domain.DocumentType,
	defaultTypes []domain.DocumentType,
	copies []domain.AppCopy,
) error

func (*DataFormatter) FormatApps added in v0.5.0

func (f *DataFormatter) FormatApps(apps []domain.App) error

func (*DataFormatter) FormatExtensionDefaults added in v0.5.0

func (f *DataFormatter) FormatExtensionDefaults(rows []domain.ExtensionDefault) error

func (*DataFormatter) FormatTargetDetails added in v0.5.0

func (f *DataFormatter) FormatTargetDetails(
	target domain.Target,
	defaultApp string,
	resolvedUTIs []string,
	availableApps []string,
) error

type Envelope added in v0.5.0

type Envelope struct {
	APIVersion int        `json:"api_version" yaml:"api_version"`
	Command    string     `json:"command" yaml:"command"`
	Data       any        `json:"data,omitempty" yaml:"data,omitempty"`
	Error      *ErrorInfo `json:"error,omitempty" yaml:"error,omitempty"`
}

Envelope is the single document every command prints with --output json or yaml: the command's data, an error, or both (e.g. a report of a set where some items failed)

type ErrorInfo added in v0.5.0

type ErrorInfo struct {
	Code     string `json:"code" yaml:"code"`
	ExitCode int    `json:"exit_code" yaml:"exit_code"`
	Message  string `json:"message" yaml:"message"`
}

ErrorInfo describes why a command failed

type Formatter

type Formatter interface {
	FormatApps(apps []domain.App) error
	FormatAppDetails(
		app domain.App,
		supportedTypes []domain.DocumentType,
		defaultTypes []domain.DocumentType,
		copies []domain.AppCopy,
	) error
	FormatTargetDetails(
		target domain.Target,
		defaultApp string,
		resolvedUTIs []string,
		availableApps []string,
	) error
	FormatExtensionDefaults(rows []domain.ExtensionDefault) error
}

Formatter formats a command's output as a table or as data for the JSON or YAML envelope

type TableFormatter

type TableFormatter struct {
	// contains filtered or unexported fields
}

TableFormatter formats output as human-readable tables

func NewTable added in v0.5.0

func NewTable(w io.Writer) *TableFormatter

NewTable returns a formatter that writes tables to w (stdout if nil)

func (*TableFormatter) FormatAppDetails

func (f *TableFormatter) FormatAppDetails(
	app domain.App,
	supportedTypes []domain.DocumentType,
	defaultTypes []domain.DocumentType,
	copies []domain.AppCopy,
) error

func (*TableFormatter) FormatApps

func (f *TableFormatter) FormatApps(apps []domain.App) error

func (*TableFormatter) FormatExtensionDefaults added in v0.2.0

func (f *TableFormatter) FormatExtensionDefaults(rows []domain.ExtensionDefault) error

func (*TableFormatter) FormatPlan

func (f *TableFormatter) FormatPlan(plan *domain.Plan) error

func (*TableFormatter) FormatTargetDetails

func (f *TableFormatter) FormatTargetDetails(
	target domain.Target,
	defaultApp string,
	resolvedUTIs []string,
	availableApps []string,
) error

type TargetDetails added in v0.5.0

type TargetDetails struct {
	Target        domain.Target `json:"target" yaml:"target"`
	DefaultApp    string        `json:"default_app,omitempty" yaml:"default_app,omitempty"`
	ResolvedUTIs  []string      `json:"resolved_utis" yaml:"resolved_utis"`
	AvailableApps []string      `json:"available_apps" yaml:"available_apps"`
}

TargetDetails is the data of targets show

type Theme

type Theme struct {
	Header      func(format string, a ...any) string
	FirstColumn func(format string, a ...any) string
	Label       func(format string, a ...any) string
	Success     func(format string, a ...any) string
	Warning     func(format string, a ...any) string
	Error       func(format string, a ...any) string
	Faint       func(format string, a ...any) string
}

Theme defines consistent styling across all formatters

Jump to

Keyboard shortcuts

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