Sha256: 8cbaeba279acd9107a84a7358da96611d48cdc87640ae713f10d40f6a5a15901

Contents?: true

Size: 882 Bytes

Versions: 6

Compression:

Stored size: 882 Bytes

Contents

require 'helpers'
require 'plugin'

require 'commands/base'


Dir["#{File.dirname(__FILE__)}/commands/*"].each { |c| require c }

module Proviso
  module Command
    class InvalidCommand < RuntimeError; end
    class CommandFailed  < RuntimeError; end

    class << self
      def run(command, args=[])
        Proviso::Plugin.load!
        run_internal(command, args)
      end
      
      def error(msg)
        STDERR.puts(msg)
        exit 1
      end
      
      
    private
      def run_internal(command, args)
        klass, method = parse(command)
        runner = klass.new(args)
        raise InvalidCommand unless runner.respond_to?(method)
        runner.send(method)
      end

      def parse(command)
        parts = command.split(':')
        return Proviso::Command.const_get(parts.first.capitalize), parts.last        
      end
            
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
proviso-0.2.0 lib/proviso/command.rb
proviso-0.2.0.beta4 lib/proviso/command.rb
proviso-0.2.0.beta3 lib/proviso/command.rb
proviso-0.2.0.beta2 lib/proviso/command.rb
proviso-0.2.0.beta1 lib/proviso/command.rb
proviso-0.1.0 lib/proviso/command.rb