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



477
478
479
# File 'lib/command-set/dsl.rb', line 477

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



483
484
485
# File 'lib/command-set/dsl.rb', line 483

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.



490
491
492
# File 'lib/command-set/dsl.rb', line 490

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.



469
470
471
472
473
# File 'lib/command-set/dsl.rb', line 469

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.



499
500
501
# File 'lib/command-set/dsl.rb', line 499

def sub_collector
  $stdout.relevant_collector.dup
end