output

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsInteractiveStdin = func() bool {
	return isatty.IsTerminal(os.Stdin.Fd()) || isatty.IsCygwinTerminal(os.Stdin.Fd())
}

IsInteractiveStdin reports whether stdin is connected to a TTY. Destructive commands check this before showing an interactive prompt so they can fail with a clear error in CI rather than silently aborting on EOF.

We resolve this through a package-level variable so tests can swap in a fixed value without touching real file descriptors.

Functions

func Bold

func Bold(msg string) string

Bold renders text in bold.

func ColorEnabled

func ColorEnabled() bool

ColorEnabled returns true if colored output is allowed.

func Confirm

func Confirm(prompt string) bool

Confirm prompts the user for y/N confirmation via stderr.

func Dim

func Dim(msg string) string

Dim renders text in gray.

func Error

func Error(msg string) string

Error renders text in red with a ✗ prefix.

func Format

func Format(cmd *cobra.Command) string

Format returns the output format from the command's --output flag.

func HumanTime

func HumanTime(t time.Time) string

HumanTime formats a timestamp as a human-friendly relative time. Times older than 30 days are shown as absolute dates.

func Info

func Info(msg string) string

Info renders text in cyan.

func InitColor

func InitColor(noColorFlag bool)

InitColor sets up color state from the --no-color flag. Call once from root PersistentPreRun.

func Print

func Print(cmd *cobra.Command, data interface{}, tableFn TableFunc) error

Print outputs data in the format specified by the --output flag. For json/yaml it marshals data directly. For table it calls tableFn. If tableFn is nil and data implements TableRenderable, the table is built automatically.

func PrintJSON

func PrintJSON(w io.Writer, data interface{}, compact bool) error

PrintJSON writes data as JSON.

func PrintTable

func PrintTable(w io.Writer, headers []string, rows [][]string, opts *TableOptions) error

PrintTable renders rows as a tab-aligned table with optional colored headers.

func PrintYAML

func PrintYAML(w io.Writer, data interface{}) error

PrintYAML writes data as YAML.

func Spin

func Spin(ctx context.Context, message string, action func() error) error

Spin shows a spinner with the given message while action runs. If stdout is not a TTY, it prints the message and runs the action without a spinner.

func Success

func Success(msg string) string

Success renders text in green with a ✓ prefix.

func Summary

func Summary(w io.Writer, shown, total int)

Summary prints a result-count summary line, e.g. "Showing 20 of 147 results".

func Table

func Table(w io.Writer, headers []string, fn func(tw *tabwriter.Writer)) error

Table creates a tabwriter, writes headers, calls fn for rows, and flushes. This preserves backward-compatibility with existing commands.

func Warn

func Warn(msg string) string

Warn renders text in yellow with a ⚠ prefix.

Types

type ProgressWriter

type ProgressWriter struct {
	Writer io.Writer
	Total  int64
	// contains filtered or unexported fields
}

ProgressWriter wraps an io.Writer and prints a progress bar to stderr.

func NewProgressWriter

func NewProgressWriter(w io.Writer, total int64, label string) *ProgressWriter

NewProgressWriter returns a writer that displays upload/download progress.

func (*ProgressWriter) Write

func (pw *ProgressWriter) Write(p []byte) (int, error)

type TableFunc

type TableFunc func(w io.Writer) error

TableFunc is a function that writes table output for a given data value.

type TableOptions

type TableOptions struct {
	NoHeader bool // Skip the header row
	Wide     bool // Show all columns (unused by default; commands define wide sets)
	MaxWidth int  // Max column width before truncation (0 = 40)
}

TableOptions controls table rendering behavior.

type TableRenderable

type TableRenderable interface {
	TableHeaders() []string
	TableRows() [][]string
}

TableRenderable can be implemented by SDK response types for automatic table rendering.

Jump to

Keyboard shortcuts

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