output

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlagNameFormat    = "format"
	FlagNameNoColor   = "no-color"
	FlagNameVerbose   = "verbose"
	FlagNameVerbosity = "verbosity"
	FlagNameQuiet     = "quiet"
	FlagNameFields    = "fields"
	FlagNameSortKey   = "sort"
	FlagNameOrder     = "order"
	FlagNameLimit     = "limit"
	FlagNameOffset    = "offset"
)
View Source
const TableRowSeparatorToken = "__melody_table_separator__"

Variables

This section is empty.

Functions

func DebugFlags

func DebugFlags() []clicontract.Flag

func MergeFlags

func MergeFlags(
	standard []clicontract.Flag,
	commandSpecific []clicontract.Flag,
) []clicontract.Flag

func Render

func Render(
	writer io.Writer,
	envelope Envelope,
	option Option,
) error

func SetApplicationVersion

func SetApplicationVersion(versionString string)

func SplitFields

func SplitFields(fieldsString string) []string

func StandardFlags

func StandardFlags() []clicontract.Flag

Types

type Envelope

type Envelope struct {
	Meta     Meta       `json:"meta"`
	Data     any        `json:"data"`
	Table    *TableData `json:"-"`
	Warnings []Warning  `json:"warnings"`
	Error    *Error     `json:"error"`
}

func NewEnvelope

func NewEnvelope(
	meta Meta,
) Envelope

func (*Envelope) AddWarning

func (instance *Envelope) AddWarning(
	code string,
	message string,
	details map[string]any,
)

func (*Envelope) SetError

func (instance *Envelope) SetError(
	code string,
	message string,
	details map[string]any,
	cause *ErrorCause,
)

type Error

type Error struct {
	Code    string         `json:"code"`
	Message string         `json:"message"`
	Details map[string]any `json:"details"`
	Cause   *ErrorCause    `json:"cause"`
}

func NewError

func NewError(code string, message string, details map[string]any, cause *ErrorCause) *Error

type ErrorCause

type ErrorCause struct {
	Message string         `json:"message"`
	Details map[string]any `json:"details"`
}

func NewErrorCause

func NewErrorCause(message string, details map[string]any) *ErrorCause

type Flags

type Flags struct {
	Format  Format    `json:"format"`
	NoColor bool      `json:"noColor"`
	Verbose bool      `json:"verbose"`
	Quiet   bool      `json:"quiet"`
	Fields  []string  `json:"fields"`
	SortKey string    `json:"sortKey"`
	Order   SortOrder `json:"order"`
	Limit   int       `json:"limit"`
	Offset  int       `json:"offset"`
}

type Format

type Format string
const (
	FormatTable Format = "table"
	FormatJson  Format = "json"
)

type JsonPrinter

type JsonPrinter struct {
}

func (*JsonPrinter) Print

func (instance *JsonPrinter) Print(
	writer io.Writer,
	envelope Envelope,
	option Option,
) error

type ListPayload

type ListPayload[T any] struct {
	Items  []T `json:"items"`
	Total  int `json:"total"`
	Limit  int `json:"limit"`
	Offset int `json:"offset"`
}

func NewListPayload

func NewListPayload[T any](
	items []T,
	total int,
	limit int,
	offset int,
) ListPayload[T]

type Meta

type Meta struct {
	Command              string    `json:"command"`
	Arguments            []string  `json:"arguments"`
	Flags                Flags     `json:"flags"`
	StartedAt            time.Time `json:"startedAt"`
	DurationMilliseconds int64     `json:"durationMilliseconds"`
	Version              Version   `json:"version"`
}

func NewMeta

func NewMeta(
	command string,
	arguments []string,
	option Option,
	startedAt time.Time,
	duration time.Duration,
	version Version,
) Meta

type Option

type Option struct {
	Format         Format
	NoColor        bool
	VerbosityLevel int
	Verbose        bool
	Quiet          bool
	Fields         []string
	SortKey        string
	Order          SortOrder
	Limit          int
	Offset         int
}

func DefaultOption

func DefaultOption() Option

func NormalizeOption

func NormalizeOption(option Option) Option

func ParseOptionFromCommand

func ParseOptionFromCommand(commandContext *clicontract.CommandContext) Option

type Printer

type Printer interface {
	Print(
		writer io.Writer,
		envelope Envelope,
		option Option,
	) error
}

func SelectPrinter

func SelectPrinter(option Option) Printer

type SortOrder

type SortOrder string
const (
	SortOrderAscending  SortOrder = "asc"
	SortOrderDescending SortOrder = "desc"
)

type TableBlock

type TableBlock struct {
	Title   string
	Columns []string
	Rows    [][]string
}

type TableBlockBuilder

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

func (*TableBlockBuilder) AddRow

func (instance *TableBlockBuilder) AddRow(cells ...string) *TableBlockBuilder

type TableBuilder

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

func NewTableBuilder

func NewTableBuilder() *TableBuilder

func (*TableBuilder) AddBlock

func (instance *TableBuilder) AddBlock(
	title string,
	columns []string,
) *TableBlockBuilder

func (*TableBuilder) AddSummaryLine

func (instance *TableBuilder) AddSummaryLine(line string) *TableBuilder

func (*TableBuilder) Build

func (instance *TableBuilder) Build() *TableData

type TableData

type TableData struct {
	SummaryLines []string
	Blocks       []TableBlock
}

type TablePrinter

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

func NewDefaultTablePrinter

func NewDefaultTablePrinter() *TablePrinter

func NewTablePrinter

func NewTablePrinter(tableMaxWidth int) *TablePrinter

func (*TablePrinter) Print

func (instance *TablePrinter) Print(
	writer io.Writer,
	envelope Envelope,
	option Option,
) error

type Version

type Version struct {
	Application string `json:"application"`
	Melody      string `json:"melody"`
	Go          string `json:"go"`
}

type Warning

type Warning struct {
	Code    string         `json:"code"`
	Message string         `json:"message"`
	Details map[string]any `json:"details"`
}

func NewWarning

func NewWarning(code string, message string, details map[string]any) Warning

Jump to

Keyboard shortcuts

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