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
|
# File 'lib/scripting/commands.rb', line 35
def self.instance_init(instance, *args)
instance.instance_eval do
options do
commands Hash.new
end
help do
$stderr.puts "\nAvailable commands:"
max_width = options.commands.keys.collect { |key| key.to_s.length }.max
options.commands.each do |k,v|
$stderr.puts sprintf(" %*s: %s", max_width, k, v.description)
end
end
work do |*args|
name = args.shift.downcase.to_sym rescue nil
command = options.commands[name]
if command.nil?
help!
puts "\nCommand: #{name} is not known"
exit
end
command.run! *args
end
end
end
|