output

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTTY

func IsTTY() bool

IsTTY returns true when os.Stdout is a real terminal.

func IsTTYWriter

func IsTTYWriter(w io.Writer) bool

IsTTYWriter returns true when w is an *os.File whose file descriptor is a real terminal. Use this instead of IsTTY() when the writer may have been redirected (e.g. cmd.OutOrStdout()).

Types

type AccessDiff

type AccessDiff struct {
	Name       string        `json:"name"             yaml:"name"`
	ChangeType string        `json:"changeType"       yaml:"changeType"`
	Server     string        `json:"server,omitempty" yaml:"server,omitempty"`
	Fields     []FieldChange `json:"fields,omitzero" yaml:"fields,omitempty"`
}

AccessDiff describes one cluster access (context) that is changing.

type ClusterSyncResult

type ClusterSyncResult struct {
	Name    string            `json:"name"             yaml:"name"`
	Context string            `json:"context"          yaml:"context"`
	Status  ClusterSyncStatus `json:"status"           yaml:"status"`
	Reason  string            `json:"reason,omitempty" yaml:"reason,omitempty"`
}

ClusterSyncResult holds per-cluster sync information.

type ClusterSyncStatus

type ClusterSyncStatus string

ClusterSyncStatus represents the sync outcome for a single cluster.

const (
	ClusterSyncStatusSynced  ClusterSyncStatus = "synced"
	ClusterSyncStatusSkipped ClusterSyncStatus = "skipped"
	ClusterSyncStatusFailed  ClusterSyncStatus = "failed"
)

type ClusterVersionResult

type ClusterVersionResult struct {
	Context string `json:"context" yaml:"context"`
	Version string `json:"version" yaml:"version"`
}

ClusterVersionResult is the output of the cluster-version command.

type DiffEntry

type DiffEntry struct {
	Name       string        `json:"name"             yaml:"name"`
	ChangeType string        `json:"changeType"       yaml:"changeType"`
	Fields     []FieldChange `json:"fields,omitzero" yaml:"fields,omitempty"`
}

DiffEntry describes a single added, removed, or modified kubeconfig entry.

type ErrorResult

type ErrorResult struct {
	Error string `json:"error" yaml:"error"`
}

ErrorResult is the structured representation of a fatal command error. It is used when the output format is json or yaml so that errors are machine-parseable in the same way as successful output.

type FieldChange

type FieldChange struct {
	Field string `json:"field" yaml:"field"`
	Old   string `json:"old"   yaml:"old"`
	New   string `json:"new"   yaml:"new"`
}

FieldChange describes a field-level change within a modified entry.

type Format

type Format string

Format represents the output format for commands.

const (
	FormatText Format = "text"
	FormatJSON Format = "json"
	FormatYAML Format = "yaml"
)

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat parses a format string and returns the corresponding Format. Returns an error for unknown values.

type Printer

type Printer interface {
	// Print formats the value v and writes it to the configured writer.
	Print(v any) error
	// PrintError writes a fatal error in the configured output format.
	// For json/yaml this produces a machine-parseable {"error":"..."} document.
	// For text this produces a plain "Error: ..." line.
	PrintError(err error)
	// StartSpinner starts a spinner with the given label and returns a stop function.
	// Calling stop() halts the spinner. In non-interactive printers this is a no-op.
	StartSpinner(label string) (stop func())
}

Printer handles formatting and writing command output.

func New

func New(format Format, isTTY bool, w io.Writer) Printer

New returns the appropriate Printer for the given format and TTY state. The writer w receives successful output (typically cmd.OutOrStdout()).

  • JSON format → jsonPrinter (no spinner)
  • YAML format → yamlPrinter (no spinner)
  • text + TTY → interactivePrinter (spinner + styled table)
  • text + non-TTY → plainPrinter (plain text, no ANSI)

func NewForError

func NewForError(format Format, errW io.Writer) Printer

NewForError returns a Printer that writes to errW (typically os.Stderr). Use this printer solely for PrintError calls when the output format is known but the success writer is separate from the error writer.

type SyncDryRunResult

type SyncDryRunResult struct {
	Accesses  []AccessDiff `json:"accesses"  yaml:"accesses"`
	Clusters  []DiffEntry  `json:"clusters"  yaml:"clusters"`
	Contexts  []DiffEntry  `json:"contexts"  yaml:"contexts"`
	AuthInfos []DiffEntry  `json:"authInfos" yaml:"authInfos"`
	Added     int          `json:"added"     yaml:"added"`
	Removed   int          `json:"removed"   yaml:"removed"`
	Modified  int          `json:"modified"  yaml:"modified"`
}

SyncDryRunResult is the output of `sync --dry-run`.

type SyncResult

type SyncResult struct {
	Clusters []ClusterSyncResult `json:"clusters" yaml:"clusters"`
	Synced   int                 `json:"synced"   yaml:"synced"`
	Skipped  int                 `json:"skipped"  yaml:"skipped"`
	Failed   int                 `json:"failed"   yaml:"failed"`
}

SyncResult is the top-level output of the sync command.

type UpdateResult

type UpdateResult struct {
	CurrentVersion string       `json:"currentVersion" yaml:"currentVersion"`
	LatestVersion  string       `json:"latestVersion"  yaml:"latestVersion"`
	Status         UpdateStatus `json:"status"         yaml:"status"`
}

UpdateResult is the output of the update command.

type UpdateStatus

type UpdateStatus string

UpdateStatus represents the outcome of an update check or install.

const (
	UpdateStatusUpToDate  UpdateStatus = "up-to-date"
	UpdateStatusAvailable UpdateStatus = "available"
	UpdateStatusUpdated   UpdateStatus = "updated"
)

type VersionInfo

type VersionInfo struct {
	Version   string `json:"version"   yaml:"version"`
	GitCommit string `json:"gitCommit" yaml:"gitCommit"`
	BuildDate string `json:"buildDate" yaml:"buildDate"`
	GoVersion string `json:"goVersion" yaml:"goVersion"`
	Compiler  string `json:"compiler"  yaml:"compiler"`
	Platform  string `json:"platform"  yaml:"platform"`
}

VersionInfo is the output of the version command.

Jump to

Keyboard shortcuts

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