Class: Beats::Command::Help::CommandGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/beats/commands/help.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ CommandGroup

Returns a new instance of CommandGroup.



34
35
36
37
# File 'lib/beats/commands/help.rb', line 34

def initialize(&block)
  @commands = []
  instance_eval(&block)
end

Instance Method Details

#command(command, description) ⇒ Object



38
39
40
# File 'lib/beats/commands/help.rb', line 38

def command(command, description)
  @commands << [command, description]
end

#display(&block) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/beats/commands/help.rb', line 41

def display(&block)
  max_length = @commands.map {|c| c.first.size }.sort.last
  @commands.each do |c|
    command, description = c.first, c.last
    yield("  #{command.ljust(max_length+2)}# #{description}")
  end
end