Class: Pvectl::Formatters::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/formatters/table.rb

Overview

Formats data as a table using tty-table gem.

For collections: renders standard horizontal table with headers. For single resources (describe): renders vertical key-value layout.

Examples:

Table output for collection

NAME    STATUS   NODE
vm-100  running  pve1
vm-101  stopped  pve2

Vertical output for single resource (describe)

Name:     vm-100
Status:   running
Node:     pve1

See Also:

Instance Method Summary collapse

Instance Method Details

#format(data, presenter, color_enabled: true, describe: false, **context) ⇒ String

Formats data as table output.

Parameters:

  • data (Array, Object)

    collection of models or single model

  • presenter (Presenters::Base)

    presenter for column/row definitions

  • color_enabled (Boolean) (defaults to: true)

    whether to apply color formatting

  • describe (Boolean) (defaults to: false)

    whether this is a describe command (single resource)

  • context (Hash)

    additional context passed to presenter

Returns:

  • (String)

    formatted table string



33
34
35
36
37
38
39
40
41
# File 'lib/pvectl/formatters/table.rb', line 33

def format(data, presenter, color_enabled: true, describe: false, **context)
  pastel = ColorSupport.pastel(explicit_flag: color_enabled)

  if describe || !collection?(data)
    format_describe(data, presenter, pastel)
  else
    format_table(data, presenter, pastel, **context)
  end
end