Class: Resedit::HelpCommand

Inherits:
AppCommand show all
Defined in:
lib/resedit/app/std_commands.rb

Instance Attribute Summary

Attributes inherited from AppCommand

#names, #ohash, #opts, #params, #type

Instance Method Summary collapse

Methods inherited from AppCommand

#addOption, #addParam, #log, #logd, #loge, #parseParams, #run

Constructor Details

#initializeHelpCommand

Returns a new instance of HelpCommand.



25
26
27
28
# File 'lib/resedit/app/std_commands.rb', line 25

def initialize
    super(['help','--help','-h','/?'])
    addParam('command', 'help on specific command', '')
end

Instance Method Details

#job(params) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/resedit/app/std_commands.rb', line 29

def job(params)
    if params['command'] != ''
        cmd = App.get().cmds[params['command']]
        raise "Unknown command: #{params['command']}" if !cmd
        puts "Command:"
        print "\t" + cmd.names[0]
        if cmd.names.length > 1
            print ' ( '
            cmd.names.each.with_index{|n,i|
                print n + ' ' if i > 0
            }
            print ')'
        end
        puts
        puts "Usage:"
        print "\t" + cmd.names[0] + ' <options>'
        cmd.params.each{|p|
            print ' '
            print '[' if p[:def] != nil
            print p[:name]
            print ']' if p[:def] != nil
        }
        puts
        puts "Params:"
        cmd.params.each{|p|
            puts "\t" + p[:name] + "\t - " + p[:descr]
        }
        puts "Options:"
        rohash = cmd.ohash.invert
        cmd.opts.each{|n, o|
            nm = "\t--"  + n
            nm += '=' if o[:param]==nil
            nm += ", -" + rohash[o[:name]] if rohash[o[:name]]
            puts nm + "\t - " + o[:descr]
        }
    else
        App.get().commands.each{|c|
            puts c.names[0]
        }
    end
end