Sha256: 54ec0a921a703e35f64199ef93197a44ebb0bf60fccb2a668ee28d6811b102e6

Contents?: true

Size: 1.1 KB

Versions: 33

Compression:

Stored size: 1.1 KB

Contents

require 'open3'
require 'thor/shell'

module Execution

  Thread.abort_on_exception = true

  def threadexec(command, prefix = nil, color = nil)

    if prefix.nil?
      # TODO: probably pick the command name without args
      prefix = 'unknown'
    end

    if color.nil?
      color = :cyan
    end

    Thread.new {
      Open3.popen3(command) do |_, stdout, stderr, _|

        # noinspection RubyAssignmentExpressionInConditionalInspection
        while line_out = stdout.gets
          say_status prefix, line_out, color
        end

        # noinspection RubyAssignmentExpressionInConditionalInspection
        while line_err = stderr.gets
          say_status prefix, line_err, :red
        end

      end
    }

  end

  # unison doesn't work when ran in a new thread
  # this functions creates a full new process instead
  def forkexec(command, prefix = nil, color = nil)

    if prefix.nil?
      # TODO: probably pick the command name without args
      prefix = 'unknown'
    end

    if color.nil?
      color = :cyan
    end

    Process.fork  {
      `#{command}` || raise(command + ' failed')
    }

  end

end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
docker-sync-0.4.6 lib/docker-sync/execution.rb
docker-sync-0.4.5 lib/docker-sync/execution.rb
docker-sync-0.4.5.beta1 lib/docker-sync/execution.rb
docker-sync-0.4.4 lib/docker-sync/execution.rb
docker-sync-0.4.4.beta2 lib/docker-sync/execution.rb
docker-sync-0.4.4.beta1 lib/docker-sync/execution.rb
docker-sync-0.4.3 lib/docker-sync/execution.rb
docker-sync-0.4.3.pre.beta1 lib/docker-sync/execution.rb
docker-sync-0.4.2 lib/docker-sync/execution.rb
docker-sync-0.4.1 lib/docker-sync/execution.rb
docker-sync-0.4.1.pre.beta2 lib/docker-sync/execution.rb
docker-sync-0.4.1.pre.beta1 lib/docker-sync/execution.rb
docker-sync-0.4.0 lib/docker-sync/execution.rb
docker-sync-0.4.0.pre.beta2 lib/docker-sync/execution.rb
docker-sync-0.4.0.pre.beta1 lib/docker-sync/execution.rb
docker-sync-0.3.6 lib/docker-sync/execution.rb
docker-sync-0.3.5 lib/docker-sync/execution.rb
docker-sync-0.3.4 lib/docker-sync/execution.rb
docker-sync-0.3.3 lib/docker-sync/execution.rb
docker-sync-0.3.2 lib/docker-sync/execution.rb