output

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package output renders command results in user-selected formats.

Supported formats: json, yaml, markdown, table, csv. The JSON and YAML renderers operate directly on the provided value (via encoding/json and gopkg.in/yaml.v3). The markdown/table/csv renderers operate on the tabular representation supplied by the caller, so each command is responsible for deciding which fields are columns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(w io.Writer, format Format, v any, t *Tabular) error

Render writes v in the given format. For markdown/table/csv, t must be supplied (JSON/YAML ignore it).

Types

type Flags

type Flags struct {
	JSON     bool
	YAML     bool
	Markdown bool
	Table    bool
	CSV      bool
}

Flags captures the mutually-exclusive format flags from Cobra. Exactly zero or one field may be true.

type Format

type Format string

Format identifies the output format.

const (
	FormatJSON     Format = "json"
	FormatYAML     Format = "yaml"
	FormatMarkdown Format = "markdown"
	FormatTable    Format = "table"
	FormatCSV      Format = "csv"
)

func Resolve

func Resolve(w io.Writer, f Flags) (Format, error)

Resolve picks a Format from the flags. If no flag is set, defaults to FormatTable on a TTY and FormatJSON otherwise.

type Tabular

type Tabular struct {
	Headers []string
	Rows    [][]string
}

Tabular is a row-oriented representation of data for markdown/table/csv formats. Values are stringified by the caller.

Jump to

Keyboard shortcuts

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