format

package
v1.16.0 Latest Latest
Warning

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

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

Documentation

Overview

Package format contains utilities for formatting and printing output, including support for spinners, colored YAML/JSON, and resource stripping.

Index

Constants

View Source
const (
	LoginCommand  = "login"
	LogoutCommand = "logout"
)
View Source
const (
	SuccessChar = "✓"
	FailureChar = "✗"
	InfoChar    = "ℹ"

	OutputFormatTypeYAML OutputFormatType = 0
	OutputFormatTypeJSON OutputFormatType = 1
)

Variables

This section is empty.

Functions

func Command added in v1.1.1

func Command() command

Command can be used to print how certain nctl commands can be executed.

func ExitIfErrorf added in v1.2.0

func ExitIfErrorf(w io.Writer, err error, args ...any) error

ExitIfErrorf prints Usage + friendly message on error (and exits).

func Failuref added in v1.14.0

func Failuref(icon, format string, a ...any) string

Failuref is a formatted message for indicating a failed step.

func InterpolateFlagPlaceholders added in v1.2.0

func InterpolateFlagPlaceholders(vars kong.Vars) func(*kong.Kong) error

InterpolateFlagPlaceholders will return a function which walks the whole kong model and interpolates variables in placeholders in flags.

func IsInteractiveEnvironment added in v1.8.2

func IsInteractiveEnvironment(out io.Writer) bool

func MissingChildren added in v1.2.0

func MissingChildren(node *kong.Node) bool

MissingChildren detects missing commands/args. Logic taken from github.com/alecthomas/kong/context.go

func PrettyPrintObject added in v1.2.2

func PrettyPrintObject(obj any, opts PrintOpts) error

PrettyPrintObject prints the supplied object in "pretty" colored yaml with some metadata, status and other default fields stripped out.

func PrettyPrintObjects

func PrettyPrintObjects[T any](objs []T, opts PrintOpts) error

PrettyPrintObjects prints the supplied objects in "pretty" colored yaml with some metadata, status and other default fields stripped out. If multiple objects are supplied, they will be divided with a yaml divider.

func Progress added in v1.14.0

func Progress(icon, message string) string

Progress is a formatted message for use with a spinner.Suffix. An icon can be added which is displayed at the end of the message.

func Progressf added in v1.14.0

func Progressf(icon, format string, a ...any) string

Progressf is a formatted message for use with a spinner.Suffix. An icon can be added which is displayed at the end of the message.

Types

type JSONOutputOptions added in v1.9.0

type JSONOutputOptions struct {
	// PrintSingleItem will print a single item of an array as is
	// (without the array notation)
	PrintSingleItem bool
}

type OutputFormatType added in v1.9.0

type OutputFormatType int

type PrintOpts

type PrintOpts struct {
	// Out will be used to print to if set instead of stdout.
	Out io.Writer
	// ExcludeAdditional allows to exclude more fields of the object
	ExcludeAdditional [][]string
	// format type of the output, e.g. yaml or json
	Format OutputFormatType
	// JSONOpts defines special options for JSON output
	JSONOpts JSONOutputOptions
	// AllFields prints all fields of the object.
	AllFields bool
}

PrintOpts customizes the printing.

type Reader added in v1.14.0

type Reader struct {
	io.Reader
}

Reader is a wrapper around an io.Reader.

func NewReader added in v1.14.0

func NewReader(r io.Reader) Reader

NewReader returns a new Reader.

func (*Reader) BeforeApply added in v1.14.0

func (r *Reader) BeforeApply(reader io.Reader) error

BeforeApply ensures that Kong initializes the Reader.

type Writer added in v1.14.0

type Writer struct {
	io.Writer
}

Writer is a wrapper around an io.Writer that provides helper methods for printing formatted messages.

func NewWriter added in v1.14.0

func NewWriter(w io.Writer) Writer

NewWriter returns a new Writer.

func (*Writer) BeforeApply added in v1.14.0

func (w *Writer) BeforeApply(writer io.Writer) error

BeforeApply ensures that Kong initializes the writer.

func (*Writer) Confirm added in v1.14.0

func (w *Writer) Confirm(reader Reader, message string) (bool, error)

Confirm prints a confirm dialog using the supplied message and then waits until prompt is confirmed or denied. Only y and yes are accepted for confirmation.

func (*Writer) Failuref added in v1.14.0

func (w *Writer) Failuref(icon string, format string, a ...any)

Failuref is a formatted message for indicating a failure.

func (*Writer) Info added in v1.14.0

func (w *Writer) Info(icon string, message string)

Info returns a message for providing information.

func (*Writer) Infof added in v1.14.0

func (w *Writer) Infof(icon string, format string, a ...any)

Infof is a formatted message for providing information.

func (*Writer) Printf added in v1.14.0

func (w *Writer) Printf(format string, a ...any)

Printf formats according to a format specifier and writes to the underlying writer. Prefer the dedicated methods if applicable.

func (*Writer) Println added in v1.14.0

func (w *Writer) Println(a ...any)

Println prints a formatted message to the underlying writer. Prefer the dedicated methods if applicable.

func (*Writer) Spinner added in v1.14.0

func (w *Writer) Spinner(message, stopMessage string) (*yacspin.Spinner, error)

Spinner creates a new spinner with the given message and stop message.

func (*Writer) Success added in v1.14.0

func (w *Writer) Success(icon string, message string)

Success returns a message for indicating a successful step.

func (*Writer) Successf added in v1.14.0

func (w *Writer) Successf(icon string, format string, a ...any)

Successf is a formatted message for indicating a successful step.

func (*Writer) Warningf added in v1.14.0

func (w *Writer) Warningf(format string, a ...any)

Warningf is a formatted message for indicating a warning.

Jump to

Keyboard shortcuts

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