Module: Pvectl::Formatters::OutputHelper
- Defined in:
- lib/pvectl/formatters/output_helper.rb
Overview
Facade for output formatting in commands.
Coordinates Formatter and Presenter to produce formatted output. Handles color flag interpretation and prints to stdout.
Class Method Summary collapse
-
.print(data:, presenter:, format: "table", color_flag: nil, describe: false, **context) ⇒ void
Formats data and prints to stdout.
-
.render(data:, presenter:, format: "table", color_flag: nil, describe: false, **context) ⇒ String
Returns formatted string without printing.
Class Method Details
.print(data:, presenter:, format: "table", color_flag: nil, describe: false, **context) ⇒ void
This method returns an undefined value.
Formats data and prints to stdout.
45 46 47 48 |
# File 'lib/pvectl/formatters/output_helper.rb', line 45 def print(data:, presenter:, format: "table", color_flag: nil, describe: false, **context) output = render(data: data, presenter: presenter, format: format, color_flag: color_flag, describe: describe, **context) puts output end |
.render(data:, presenter:, format: "table", color_flag: nil, describe: false, **context) ⇒ String
Returns formatted string without printing.
Useful for testing or when you need to manipulate the output before displaying.
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pvectl/formatters/output_helper.rb', line 62 def render(data:, presenter:, format: "table", color_flag: nil, describe: false, **context) formatter = Registry.for(format) color_enabled = ColorSupport.enabled?(explicit_flag: color_flag) formatter.format( data, presenter, color_enabled: color_enabled, describe: describe, **context ) end |