Class: Hammer::CommandBuilder
- Inherits:
-
Object
- Object
- Hammer::CommandBuilder
- Defined in:
- lib/hammer/command_builder.rb
Overview
Context object for ‘define :name do … end` blocks. Exposes desc/example/opt/alt; the block’s return value (a ‘proc do |opts|`) becomes the command handler.
Instance Method Summary collapse
- #alt(*names) ⇒ Object
- #desc(text) ⇒ Object
- #example(text) ⇒ Object
-
#initialize(cmd) ⇒ CommandBuilder
constructor
A new instance of CommandBuilder.
- #needs(*names) ⇒ Object
- #opt(name, **opts) ⇒ Object
Constructor Details
#initialize(cmd) ⇒ CommandBuilder
Returns a new instance of CommandBuilder.
6 7 8 |
# File 'lib/hammer/command_builder.rb', line 6 def initialize(cmd) @cmd = cmd end |
Instance Method Details
#alt(*names) ⇒ Object
22 23 24 |
# File 'lib/hammer/command_builder.rb', line 22 def alt(*names) names.each { |n| @cmd.add_alt(n) } end |
#desc(text) ⇒ Object
10 11 12 |
# File 'lib/hammer/command_builder.rb', line 10 def desc(text) @cmd.instance_variable_set(:@desc, text.to_s.rstrip) end |
#example(text) ⇒ Object
14 15 16 |
# File 'lib/hammer/command_builder.rb', line 14 def example(text) @cmd.add_example(text) end |
#needs(*names) ⇒ Object
26 27 28 |
# File 'lib/hammer/command_builder.rb', line 26 def needs(*names) names.each { |n| @cmd.add_need(n) } end |