Documentation
¶
Index ¶
- Constants
- func ApplySortOrder[T any](items []T, order SortOrder)
- func DebugFlags() []clicontract.Flag
- func IsJsonFormat(format Format) bool
- func MergeFlags(standard []clicontract.Flag, commandSpecific []clicontract.Flag) []clicontract.Flag
- func Render(writer io.Writer, envelope Envelope, option Option) error
- func ReverseItems[T any](items []T)
- func SetApplicationVersion(versionString string)
- func StandardFlags() []clicontract.Flag
- func WindowItems[T any](items []T, limit int, offset int) []T
- type Envelope
- type Error
- type ErrorCause
- type Flags
- type Format
- type JsonPrinter
- type ListPayload
- type Meta
- type Option
- type Printer
- type SortOrder
- type TableBlock
- type TableBlockBuilder
- type TableBuilder
- type TableData
- type TablePrinter
- type Version
- type Warning
Constants ¶
const ( FlagNameFormat = "format" FlagNameNoColor = "no-color" FlagNameVerbose = "verbose" FlagNameVerbosity = "verbosity" FlagNameQuiet = "quiet" FlagNameOrder = "order" FlagNameLimit = "limit" FlagNameOffset = "offset" FlagNameTableMaxWidth = "table-width" )
const TableRowSeparatorToken = "__melody_table_separator__"
Variables ¶
This section is empty.
Functions ¶
func ApplySortOrder ¶ added in v2.13.0
func DebugFlags ¶
func DebugFlags() []clicontract.Flag
DebugFlags returns StandardFlags with quiet defaulting to false: an introspection command exists to be read by a person, so the headers and context quiet suppresses are part of its answer.
func IsJsonFormat ¶ added in v2.13.0
IsJsonFormat answers for both json spellings, and every place that used to compare against FormatJson asks through it: the two differ in whitespace alone, so a site that recognises one and not the other would color a banner into a document, or print a table where a document was asked for.
func MergeFlags ¶
func MergeFlags( standard []clicontract.Flag, commandSpecific []clicontract.Flag, ) []clicontract.Flag
func ReverseItems ¶ added in v2.13.0
func ReverseItems[T any](items []T)
ReverseItems turns an ascending sort into a descending one in place. It runs before WindowItems so a descending --limit returns the tail of the ascending order rather than its head.
func SetApplicationVersion ¶
func SetApplicationVersion(versionString string)
SetApplicationVersion declares the running application's own version to every command envelope: the meta of each rendered document and the application row of debug:version read it. An application calls this once from its composition root before Run, with the version it keeps wherever it keeps it — its own ldflags variable, its environment, a file. Undeclared, the application version renders empty in the meta and as <unknown> in debug:version; nothing substitutes melody's version for it.
func StandardFlags ¶
func StandardFlags() []clicontract.Flag
StandardFlags returns the flag set every melody command accepts. Quiet defaults to true on purpose: a command's essential output — the document, table or summary the command exists to produce — is never gated on quiet, so the flag governs only headers and decoration, and the default keeps a scripted invocation clean without asking for it.
func WindowItems ¶ added in v2.13.0
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"`
}
Envelope is not safe for concurrent use: a command that gathers warnings from parallel work funnels them through one goroutine rather than calling AddWarning from several.
func NewEnvelope ¶
func (*Envelope) AddWarning ¶
type Error ¶
type Error struct {
Code string `json:"code"`
Message string `json:"message"`
Details map[string]any `json:"details"`
Cause *ErrorCause `json:"cause"`
}
type ErrorCause ¶
func NewErrorCause ¶
func NewErrorCause(message string, details map[string]any) *ErrorCause
type Format ¶
type Format string
const ( FormatTable Format = "table" FormatJson Format = "json" /* FormatJsonPretty is the same document indented for a person reading it by hand. It exists because json is the machine format and a machine reads a stream: one document per line, so a consumer can follow a long-running command live with a line reader and hand each line to a parser whole. Indenting by default made every document many lines, which every line-framed consumer — a log collector's json stage, a `while read line`, a `grep '"failed": true'` — receives as fragments that each fail to parse. */ FormatJsonPretty Format = "json-pretty" )
type JsonPrinter ¶
type JsonPrinter struct {
}
func (*JsonPrinter) Print ¶
the document is written on ONE line, terminated by the encoder's own newline, so a stream of them is a stream of records a line reader can hand to a parser whole — which is what a long-running command under --format=json is for, and what its own documentation promised while the indentation made every document a block of twenty. FormatJsonPretty is the same document with the indentation back, for the person reading it by hand; `| jq` does the same for a pipeline that already has it.
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 Option ¶
type Option struct {
Format Format
NoColor bool
VerbosityLevel int
Verbose bool
Quiet bool
Order SortOrder
Limit int
Offset int
TableMaxWidth int
}
func DefaultOption ¶
func DefaultOption() Option
func NormalizeOption ¶
func ParseOptionFromCommand ¶
func ParseOptionFromCommand(commandContext *clicontract.CommandContext) Option
type Printer ¶
func SelectPrinter ¶
type TableBlock ¶
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
}
TableBuilder is not safe for concurrent use: a command that assembles its table from parallel work funnels the rows through one goroutine — a channel the workers send to — rather than sharing the builder between them.
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