Module: Command::DSL::Formatting

Included in:
Action
Defined in:
lib/command-set/dsl.rb

Overview

The DSL for formatting. A lot of code will do just fine with the Kernel#puts #that Results intercepts. More involved output control starts by including CommandSet::DSL::Formatting, and using Formatting#list and Formatting#item to structure output for the formatters.

Instance Method Summary collapse

Instance Method Details

#begin_list(name, options = {}) ⇒ Object

Tells the main collector to begin a list. Subsequent output will be gathered into that list. For more, check out Results::Collector



466
467
468
# File 'lib/command-set/dsl.rb', line 466

def begin_list(name, options={})
  $stdout.relevant_collector.begin_list(name, options)
end

#end_listObject

Tells the main collector to end the current list. For more, check out Results::Collector



472
473
474
# File 'lib/command-set/dsl.rb', line 472

def end_list  
  $stdout.relevant_collector.end_list
end

#item(name, options = {}) ⇒ Object

Clean way to create an item of output. Allows for various options to be added. The normal output method (#puts, #p, #write…) are all diverted within a command, and effectively create no-option items.



479
480
481
# File 'lib/command-set/dsl.rb', line 479

def item(name, options={})
  $stdout.relevant_collector.item(name, options)
end

#list(name, options = {}) ⇒ Object

To create lists and sublist of data, you can use #list to wrap code in a #begin_list / #end_list pair.



458
459
460
461
462
# File 'lib/command-set/dsl.rb', line 458

def list(name, options={}) #:yield: 
  begin_list(name, options)
  yield if block_given?
  end_list
end

#sub_collectorObject

This returns a new Results::Collector, which can allow for some very sophisticated command output. Specifically, it can allow a command to loop over a large amount of data once, depositing output in multiple lists at once, for instance a status list (with hashmarks) and results(with useful data) list.



488
489
490
# File 'lib/command-set/dsl.rb', line 488

def sub_collector
  $stdout.relevant_collector.dup
end