Sha256: 6208ac82ed6deee03637b591b3e11c6a6af13d77c3d223a23e2ba15707c64a7c

Contents?: true

Size: 984 Bytes

Versions: 16

Compression:

Stored size: 984 Bytes

Contents

require 'commands/base'

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

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

    class << self
      def run(command, args)
        begin
          run_internal(command, args.dup)
        rescue InvalidCommand
          error "Unknown command. Run 'cloudkick help' for usage information."
        rescue CommandFailed => e
          error e.message
        rescue Interrupt => e
          error "\n[canceled]"
        end
      end

      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 error(msg)
        STDERR.puts(msg)
        exit 1
      end

      def parse(command)
        return eval("Cloudkick::Command::#{command.capitalize}"), :index
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
cloudkick-0.2.16 lib/cloudkick/command.rb
cloudkick-0.2.15 lib/cloudkick/command.rb
cloudkick-0.2.14 lib/cloudkick/command.rb
cloudkick-0.2.13 lib/cloudkick/command.rb
cloudkick-0.2.12 lib/cloudkick/command.rb
cloudkick-0.2.11 lib/cloudkick/command.rb
cloudkick-0.2.10 lib/cloudkick/command.rb
cloudkick-0.2.9 lib/cloudkick/command.rb
cloudkick-0.2.8 lib/cloudkick/command.rb
cloudkick-0.2.7 lib/cloudkick/command.rb
cloudkick-0.2.6 lib/cloudkick/command.rb
cloudkick-0.2.5 lib/cloudkick/command.rb
cloudkick-0.2.4 lib/cloudkick/command.rb
cloudkick-0.2.3 lib/cloudkick/command.rb
cloudkick-0.2.2 lib/cloudkick/command.rb
cloudkick-0.2.1 lib/cloudkick/command.rb