require 'em-eventsource' module Gisha class Commands::Deploy attr_accessor :url, :key_id, :repo_path, :revision def initialize(url, key_id, repo_path, revision) @url = url @key_id = key_id @repo_path = repo_path @revision = revision end def exec EM.run do source = EventMachine::EventSource.new(url) source.on('progress') do |message| write(message) end source.on('completed') do |message| source.close EM.stop end source.error do |error| write(error) source.close EM.stop raise ArgumentError, error end source.start end end private def repo_name repo_path.split('/').last end def write(msg) @stdout ||= begin $stdout.sync = true $stdout end @stdout.write "\e[1G-----> #{msg}\n" end end end