output

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFlags

func AddFlags(cmd *cobra.Command, o *Options, availableFields []string)

AddFlags registers --json, --jq, --template, and --limit flags on the given command.

func AddFlagsNoLimit

func AddFlagsNoLimit(cmd *cobra.Command, o *Options, availableFields []string)

AddFlagsNoLimit registers --json, --jq, --template flags but NOT --limit.

func ApplyLimit

func ApplyLimit[T any](items []T, limit int) []T

ApplyLimit trims a slice to at most limit items. If limit <= 0 the slice is returned unchanged.

func IsTerminal

func IsTerminal() bool

IsTerminal returns true when stdout is a terminal (not piped).

Types

type Options

type Options struct {
	JSON     string // comma-separated field names, or empty for all fields
	Jq       string // jq expression to filter JSON output
	Template string // Go template string to format JSON output
	Limit    int    // maximum number of items (0 = unlimited)
}

Options holds the output-related flags shared across list/view commands.

func (*Options) IsJSON

func (o *Options) IsJSON() bool

IsJSON returns true when any JSON output has been requested.

func (*Options) PrintJSON

func (o *Options) PrintJSON(v any) error

PrintJSON serializes items as a JSON array (or single object for non-slice types), optionally filtering to the requested fields, then applies --jq or --template if set.

func (*Options) RequestedFields

func (o *Options) RequestedFields() map[string]bool

RequestedFields parses --json into a set of field names. Returns nil when all fields should be included (--json with no value, or --json *).

Jump to

Keyboard shortcuts

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