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
-
#begin_list(name, options = {}) ⇒ Object
Tells the main collector to begin a list.
-
#end_list ⇒ Object
Tells the main collector to end the current list.
-
#item(name, options = {}) ⇒ Object
Clean way to create an item of output.
-
#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.
-
#sub_collector ⇒ Object
This returns a new Results::Collector, which can allow for some very sophisticated command output.
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
473 474 475 |
# File 'lib/command-set/dsl.rb', line 473 def begin_list(name, ={}) $stdout.relevant_collector.begin_list(name, ) end |
#end_list ⇒ Object
Tells the main collector to end the current list. For more, check out Results::Collector
479 480 481 |
# File 'lib/command-set/dsl.rb', line 479 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.
486 487 488 |
# File 'lib/command-set/dsl.rb', line 486 def item(name, ={}) $stdout.relevant_collector.item(name, ) 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.
465 466 467 468 469 |
# File 'lib/command-set/dsl.rb', line 465 def list(name, ={}) #:yield: begin_list(name, ) yield if block_given? end_list end |
#sub_collector ⇒ Object
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.
495 496 497 |
# File 'lib/command-set/dsl.rb', line 495 def sub_collector $stdout.relevant_collector.dup end |