output

package
v3.58.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorEnabled added in v3.17.0

func ColorEnabled() bool

ColorEnabled returns false when the NO_COLOR environment variable is present See https://no-color.org for the convention

func Table added in v3.17.0

func Table(headers []string, rows [][]string, columnStyles map[string]string) string

func ValueOrDash added in v3.17.0

func ValueOrDash(s string) string

func Write

func Write(w io.Writer, v interface{}, format Format) error

Write outputs the given value in the specified format to the writer

func WriteTextOrStructured added in v3.35.2

func WriteTextOrStructured(w io.Writer, format Format, structuredValue interface{}, text string) error

WriteTextOrStructured writes a human-readable text line for text output and structured output for JSON or YAML formats.

Types

type Format

type Format string

Format represents the output format type

const (
	// FormatJSON outputs in JSON format
	FormatJSON Format = "json"
	// FormatYAML outputs in YAML format
	FormatYAML Format = "yaml"
	// FormatText outputs in plain text/default format
	FormatText    Format = "text"
	DefaultFormat Format = FormatJSON
)

func ResolveFormat added in v3.22.0

func ResolveFormat(flagValue, configValue string) Format

ResolveFormat determines the output format to use. Priority: flagValue (if set) > configValue > DefaultFormat

type Formatter

type Formatter interface {
	// TextOutput returns the plain text representation
	TextOutput() string
}

Formatter is an interface that types must implement to support formatted output

type OutputFlags added in v3.29.0

type OutputFlags struct {
	JSON   bool   `help:"Output as JSON" xor:"format"`
	YAML   bool   `help:"Output as YAML" xor:"format"`
	Text   bool   `help:"Output as text" xor:"format"`
	Output string `help:"Output format. One of: json, yaml, text" short:"o" default:"${output_default_format}" enum:",json,yaml,text"`
}

OutputFlags provides shorthand flags for output format selection. Embed this struct in command structs to get --json, --yaml, --text flags in addition to the existing --output/-o flag.

func (*OutputFlags) AfterApply added in v3.29.0

func (o *OutputFlags) AfterApply() error

AfterApply is called by Kong after parsing to map boolean flags to the Output string.

type Viewable added in v3.17.0

type Viewable[T any] struct {
	Data   T
	Render func(T) string
}

Viewable wraps any type to provide formatted output support. It delegates JSON/YAML marshaling directly to the underlying data, while using a custom render function for text output.

func (Viewable[T]) MarshalJSON added in v3.17.0

func (v Viewable[T]) MarshalJSON() ([]byte, error)

MarshalJSON delegates JSON marshaling to the underlying data.

func (Viewable[T]) MarshalYAML added in v3.17.0

func (v Viewable[T]) MarshalYAML() (interface{}, error)

MarshalYAML delegates YAML marshaling to the underlying data.

func (Viewable[T]) TextOutput added in v3.17.0

func (v Viewable[T]) TextOutput() string

TextOutput implements the Formatter interface for text output.

Jump to

Keyboard shortcuts

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