output

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package output provides formatters for displaying Foundry resources in various formats (table, YAML, JSON).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateFormat

func ValidateFormat(format string) error

ValidateFormat checks if a format string is valid.

Types

type Format

type Format string

Format represents an output format type.

const (
	// FormatTable is a human-readable table format.
	FormatTable Format = "table"
	// FormatYAML is a YAML format for declarative configs.
	FormatYAML Format = "yaml"
	// FormatJSON is a JSON format for machine consumption.
	FormatJSON Format = "json"
)

type Formatter

type Formatter interface {
	// FormatVM formats a single VirtualMachine resource.
	FormatVM(vm *v1alpha1.VirtualMachine) (string, error)

	// FormatVMList formats a list of VirtualMachine resources.
	FormatVMList(vms []*v1alpha1.VirtualMachine) (string, error)
}

Formatter formats Foundry resources for output.

func NewFormatter

func NewFormatter(opts Options) (Formatter, error)

NewFormatter creates a new Formatter based on the specified format.

type JSONFormatter

type JSONFormatter struct{}

JSONFormatter formats resources as JSON.

func (*JSONFormatter) FormatVM

func (f *JSONFormatter) FormatVM(vm *v1alpha1.VirtualMachine) (string, error)

FormatVM formats a single VirtualMachine as JSON.

func (*JSONFormatter) FormatVMList

func (f *JSONFormatter) FormatVMList(vms []*v1alpha1.VirtualMachine) (string, error)

FormatVMList formats a list of VirtualMachines as JSON. Outputs as a JSON array.

func (*JSONFormatter) FormatVMListAsItems

func (f *JSONFormatter) FormatVMListAsItems(vms []*v1alpha1.VirtualMachine) (string, error)

FormatVMListAsItems formats a list of VirtualMachines as a JSON object with items array. This mimics Kubernetes List format:

{
  "apiVersion": "foundry.cofront.xyz/v1alpha1",
  "kind": "VirtualMachineList",
  "items": [...]
}

type Options

type Options struct {
	// Format specifies the output format.
	Format Format
	// NoHeaders omits headers in table format.
	NoHeaders bool
}

Options contains options for formatting output.

type TableFormatter

type TableFormatter struct {
	// NoHeaders omits the header row.
	NoHeaders bool
}

TableFormatter formats resources as human-readable tables.

func (*TableFormatter) FormatVM

func (f *TableFormatter) FormatVM(vm *v1alpha1.VirtualMachine) (string, error)

FormatVM formats a single VirtualMachine as a table row.

func (*TableFormatter) FormatVMList

func (f *TableFormatter) FormatVMList(vms []*v1alpha1.VirtualMachine) (string, error)

FormatVMList formats a list of VirtualMachines as a table.

type YAMLFormatter

type YAMLFormatter struct{}

YAMLFormatter formats resources as YAML.

func (*YAMLFormatter) FormatVM

func (f *YAMLFormatter) FormatVM(vm *v1alpha1.VirtualMachine) (string, error)

FormatVM formats a single VirtualMachine as YAML.

func (*YAMLFormatter) FormatVMList

func (f *YAMLFormatter) FormatVMList(vms []*v1alpha1.VirtualMachine) (string, error)

FormatVMList formats a list of VirtualMachines as YAML. Outputs as a YAML stream (multiple documents separated by ---).

Jump to

Keyboard shortcuts

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