Class: GridCLI::HelpCommand

Inherits:
BaseCommand show all
Defined in:
lib/gridcli/commands/help.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#cmd, #desc

Instance Method Summary collapse

Methods inherited from BaseCommand

#add_format_option, #add_option, #error, #log, #output_format, #parse_dates, #parse_opts, #pop_arg, #pprint, #usage

Constructor Details

#initializeHelpCommand

Returns a new instance of HelpCommand.



3
4
5
# File 'lib/gridcli/commands/help.rb', line 3

def initialize
  super "help", "Show available commands"
end

Instance Method Details

#run(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gridcli/commands/help.rb', line 7

def run(args)
  if args.length > 0
    cmd = Runner.command(args.first)
    cmd.new.usage if not cmd.nil?
  end

  puts "Usage: grid <cmd>\n\nAvailable commands:\n\n"
  Runner.commands.sort { |a,b| a.to_s <=> b.to_s }.each { |klass|
    inst = klass.new
    puts "\t#{inst.cmd.ljust(25) + inst.desc}"
  }
  puts "\n\nTo get the options for any individual command, use:"
  puts "\tgrid help <cmd>\n\n"
end