Class: Hammer::CommandBuilder

Inherits:
Object
  • Object
show all
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

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

#opt(name, **opts) ⇒ Object



18
19
20
# File 'lib/hammer/command_builder.rb', line 18

def opt(name, **opts)
  @cmd.add_option(Option.new(name, **opts))
end