output

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package output provides structured output formatting for the stackctl CLI. Commands use this package to print results in table, JSON, or YAML format depending on the --output / -o flag set by the user.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsStructured

func IsStructured() bool

IsStructured returns true when the current format is not table (i.e. machine-readable). Commands can use this to suppress emoji/decorative output.

func PrintList

func PrintList(title string, headers []string, items []ListItem)

PrintList prints a titled list of items using the global format.

func PrintRecord

func PrintRecord(title string, item ListItem)

PrintRecord prints a single record (key/value pairs) using the global format.

func PrintSecretMap

func PrintSecretMap(path string, data map[string]any)

PrintSecretMap prints a map of secret key/values (e.g. vault secret get).

func PrintStatus

func PrintStatus(r StatusResult)

PrintStatus prints a success/failure status with optional detail fields.

func PrintValue

func PrintValue(key, value string)

PrintValue prints a single named value (e.g. generated password).

func Set

func Set(format Format)

Set configures the global printer format. Called once from root.go.

func SetWriter

func SetWriter(format Format, w io.Writer)

SetWriter configures the global printer with the given format and writer. Intended for use in tests to capture output without touching os.Stdout.

Types

type Format

type Format string

Format represents the output format selected by the user.

const (
	FormatTable Format = "table"
	FormatJSON  Format = "json"
	FormatYAML  Format = "yaml"
)

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat converts a string to a Format, returning an error for unknown values.

type ListItem

type ListItem struct {
	Pairs []Pair
}

ListItem represents a single row in a tabular list. Keys are preserved in insertion order via the ordered Pairs slice.

func NewItem

func NewItem(keyValues ...string) ListItem

NewItem builds a ListItem from alternating key, value arguments.

type Pair

type Pair struct {
	Key   string
	Value string
}

Pair is a single key/value field.

type Printer

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

Printer writes structured data to an output stream in the configured format.

func Get

func Get() *Printer

Get returns the global printer.

func (*Printer) PrintList

func (p *Printer) PrintList(title string, headers []string, items []ListItem)

func (*Printer) PrintRecord

func (p *Printer) PrintRecord(title string, item ListItem)

func (*Printer) PrintSecretMap

func (p *Printer) PrintSecretMap(path string, data map[string]any)

func (*Printer) PrintStatus

func (p *Printer) PrintStatus(r StatusResult)

func (*Printer) PrintValue

func (p *Printer) PrintValue(key, value string)

type StatusResult

type StatusResult struct {
	Success bool
	Message string
	Fields  ListItem
}

StatusResult holds the result of an operation (e.g. test-user).

Jump to

Keyboard shortcuts

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