Class: Greenhouse::Commands::Help

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/greenhouse/commands/help.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Command

included

Class Method Details

.usageObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/greenhouse/commands/help.rb', line 11

def self.usage
  puts <<USAGE
usage: #{::Greenhouse::CLI.command_name} #{command_name} <command>

The available greenhouse commands are:
USAGE
  
  Commands::commands.select { |cmd| cmd != self}.each do |cmd|
    print "   %-#{Commands::commands.sort { |a,b| a.command_name.length <=> b.command_name.length }.last.command_name.length + 2}s" % cmd.command_name
    puts "# #{cmd.command_summary}"
  end
end

Instance Method Details

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/greenhouse/commands/help.rb', line 24

def run
  if arguments.empty?
    usage
    return
  end

  begin
    cmd = Commands::commands.select { |cmd| cmd.command_name == arguments.first.key.underscore }.first
    raise if cmd.nil?

    puts cmd.command_summary
    puts
    print "    "
    cmd.usage
  rescue
    puts "Invalid Command: #{arguments.first.key.underscore}"
    usage
  end
end