Class: HelpCommand

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

Instance Attribute Summary

Attributes inherited from Command

#description

Instance Method Summary collapse

Methods inherited from Command

#after_init, #before_init, default_cmd, describe, description, get_allowed_commands, #help, #initialize, load, load_all, #run, show_use, usage

Constructor Details

This class inherits a constructor from Command

Instance Method Details

#mainObject

description “Shows the current help screen” usage “rcli help <command>”



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/commands/help.rb', line 6

def main
  
  if Rcli.script_config['global']['mode'] == 'single'
    cmdname = Rcli.script_config['global']['default_command']
    cmd = Command.load(cmdname)
    cmd[cmdname][:instance].help
  else
    if @params[:args].size == 0
      puts
      puts Rcli.script_config['global']['description']
      puts
      puts "usage:\n     " + self.class.show_use
      puts
      
      commands = Command.load_all

      # require Rcli.script_root + DS + 'lib' + DS + 'commands' + DS + 'help'
      # pp ::HelpCommand.describe ; exit

      puts "Commands currently implemented are:"
  
      # calculate column width
      biggest = 0
      commands.each { |c,data| biggest = c.size if biggest < c.size }

      commands.sort.each do |name,cmd|
        next if name == 'help'
        # puts "#{name}, :: #{cmd}"
        puts "  %-#{biggest}s" % name + "  " + cmd[:instance].class.describe if name != 'debug'
      end
  
      puts 
      puts "Type '#{Rcli.script_config['global']['script_name']} help COMMAND' for instructions on using a specific command"
      puts 
    else
      cmd = Command.load(@params[:args][0])
    
      cmd[@params[:args][0]][:instance].help
    end
  end
end