cmdutil

package
v1.1.14 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package cmdutil provides common utilities for CLI commands

Index

Constants

View Source
const OutputFlag = "output"

OutputFlag is the standard output format flag name

Variables

This section is empty.

Functions

func AddOutputFlag

func AddOutputFlag(cmd *cobra.Command, format *string)

AddOutputFlag adds the standard --output/-o flag to a command

func NewOutput

func NewOutput(format string) *tui.Output

NewOutput creates a new Output instance from the format string

func Render

func Render(out *tui.Output, r Renderable) error

Render outputs the data based on the format (JSON or TUI)

Types

type ActionData

type ActionData struct {
	Success bool
	Message string
	ID      string
}

ActionData represents the result of an action (create, update, delete, etc.)

func (*ActionData) RenderJSON

func (a *ActionData) RenderJSON() any

func (*ActionData) RenderTUI

func (a *ActionData) RenderTUI(out *tui.Output)

type CompositeData

type CompositeData struct {
	JSON  any          // JSON representation
	Parts []Renderable // TUI parts rendered in order
}

CompositeData allows combining multiple renderables

func (*CompositeData) RenderJSON

func (c *CompositeData) RenderJSON() any

func (*CompositeData) RenderTUI

func (c *CompositeData) RenderTUI(out *tui.Output)

type DetailData

type DetailData[T any] struct {
	Title    string
	Item     T
	ItemFunc func(item T, out *tui.Output) // Custom TUI rendering
}

DetailData represents detailed information about a single item

func (*DetailData[T]) RenderJSON

func (d *DetailData[T]) RenderJSON() any

func (*DetailData[T]) RenderTUI

func (d *DetailData[T]) RenderTUI(out *tui.Output)

type ListData

type ListData[T any] struct {
	Items   []T
	Headers []string
	RowFunc func(item T, styles *tui.Styles) []string // Convert item to row
	Empty   string
}

ListData represents a list of items with table rendering

func (*ListData[T]) RenderJSON

func (l *ListData[T]) RenderJSON() any

func (*ListData[T]) RenderTUI

func (l *ListData[T]) RenderTUI(out *tui.Output)

type MessageData

type MessageData struct {
	Type    string // "success", "error", "info", "warning"
	Message string
	JSON    any // Optional custom JSON
}

MessageData represents a simple message (success, error, info, warning)

func (*MessageData) RenderJSON

func (m *MessageData) RenderJSON() any

func (*MessageData) RenderTUI

func (m *MessageData) RenderTUI(out *tui.Output)

type ProgressData

type ProgressData struct {
	Operation string
	Target    string
	Progress  float64
	Total     int64
	Current   int64
}

ProgressData represents progress information (for operations like download)

func (*ProgressData) RenderJSON

func (p *ProgressData) RenderJSON() any

func (*ProgressData) RenderTUI

func (p *ProgressData) RenderTUI(out *tui.Output)

type Renderable

type Renderable interface {
	// RenderJSON returns the data structure for JSON output
	RenderJSON() any
	// RenderTUI renders the TUI output using the provided Output
	RenderTUI(out *tui.Output)
}

Renderable is an interface for types that can render themselves in both JSON and TUI formats

type StatusData

type StatusData struct {
	Title string
	Items []StatusItem
	JSON  any // Custom JSON representation (optional)
}

StatusData represents key-value status information

func (*StatusData) RenderJSON

func (s *StatusData) RenderJSON() any

func (*StatusData) RenderTUI

func (s *StatusData) RenderTUI(out *tui.Output)

type StatusItem

type StatusItem struct {
	Key    string
	Value  string
	Status string // Optional status for styling
}

StatusItem represents a single status key-value pair

type TableData

type TableData struct {
	Headers []string
	Rows    [][]string
	Empty   string // Message when no rows
}

TableData represents data that can be rendered as a table

func (*TableData) RenderJSON

func (t *TableData) RenderJSON() any

func (*TableData) RenderTUI

func (t *TableData) RenderTUI(out *tui.Output)

Jump to

Keyboard shortcuts

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