Module: Scripting::Commands

Defined in:
lib/scripting/commands.rb

Defined Under Namespace

Modules: InstanceMethods Classes: Command

Class Method Summary collapse

Class Method Details

.instance_init(instance, *args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/scripting/commands.rb', line 36

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
      run_command! name, *args
    end
  end
end