Documentation
¶
Index ¶
- Constants
- Variables
- func Print(data interface{}) error
- func PrintJSON(data interface{}) error
- func PrintTemplate(tpl string, v interface{}) error
- func PrintYAML(data interface{}) error
- func SetGlobalFormat(format OutputFormat)
- func Table(header []string, data [][]string)
- type OutputFormat
- type OutputManager
- func (o *OutputManager) GetFormat() OutputFormat
- func (o *OutputManager) Print(data interface{}) error
- func (o *OutputManager) PrintJSON(data interface{}) error
- func (o *OutputManager) PrintTable(headers []string, rows [][]string) error
- func (o *OutputManager) PrintTableFromStructs(data interface{}) error
- func (o *OutputManager) PrintYAML(data interface{}) error
- func (o *OutputManager) SetFormat(format OutputFormat)
- type OutputOption
Constants ¶
const ( CommandDescribeTemplate = ` ID: {{.ID}} Name: {{.Name}} ` GuildDescribeTemplate = `` /* 174-byte string literal not displayed */ )
Variables ¶
var DefaultOutputManager = NewOutputManager()
DefaultOutputManager is the global default output manager
Functions ¶
func PrintJSON ¶
func PrintJSON(data interface{}) error
PrintJSON uses the default output manager to print JSON
func PrintTemplate ¶
func PrintYAML ¶
func PrintYAML(data interface{}) error
PrintYAML uses the default output manager to print YAML
func SetGlobalFormat ¶
func SetGlobalFormat(format OutputFormat)
SetGlobalFormat sets the format for the default output manager
Types ¶
type OutputFormat ¶
type OutputFormat string
OutputFormat represents the output format type
const ( // FormatTable outputs data as a formatted table (default) FormatTable OutputFormat = "table" // FormatJSON outputs data as JSON FormatJSON OutputFormat = "json" // FormatYAML outputs data as YAML FormatYAML OutputFormat = "yaml" )
func ParseFormat ¶
func ParseFormat(s string) (OutputFormat, error)
ParseFormat parses a string into an OutputFormat Falls back to table format for unknown formats
func (OutputFormat) String ¶
func (f OutputFormat) String() string
String returns the string representation of the format
type OutputManager ¶
type OutputManager struct {
// contains filtered or unexported fields
}
OutputManager handles output formatting for different data types
func NewOutputManager ¶
func NewOutputManager(opts ...OutputOption) *OutputManager
NewOutputManager creates a new OutputManager with the given options
func (*OutputManager) GetFormat ¶
func (o *OutputManager) GetFormat() OutputFormat
GetFormat returns the current output format
func (*OutputManager) Print ¶
func (o *OutputManager) Print(data interface{}) error
Print outputs data based on the configured format For table format, use PrintTable with headers and rows For JSON/YAML, pass a struct, slice, or map
func (*OutputManager) PrintJSON ¶
func (o *OutputManager) PrintJSON(data interface{}) error
PrintJSON outputs data as formatted JSON
func (*OutputManager) PrintTable ¶
func (o *OutputManager) PrintTable(headers []string, rows [][]string) error
PrintTable outputs data as a formatted table
func (*OutputManager) PrintTableFromStructs ¶
func (o *OutputManager) PrintTableFromStructs(data interface{}) error
PrintTableFromStructs outputs a slice of structs as a table Uses struct tags to determine column names
func (*OutputManager) PrintYAML ¶
func (o *OutputManager) PrintYAML(data interface{}) error
PrintYAML outputs data as formatted YAML
func (*OutputManager) SetFormat ¶
func (o *OutputManager) SetFormat(format OutputFormat)
SetFormat changes the output format
type OutputOption ¶
type OutputOption func(*OutputManager)
OutputOption configures the OutputManager
func WithFormat ¶
func WithFormat(format OutputFormat) OutputOption
WithFormat sets the output format
func WithWriter ¶
func WithWriter(w io.Writer) OutputOption
WithWriter sets the output writer (defaults to os.Stdout)