Sha256: df04800edd9db2d819fce5a42e49083b8d5aaaebc6f49953afb6ed85a17e9871
Contents?: true
Size: 647 Bytes
Versions: 4
Compression:
Stored size: 647 Bytes
Contents
require 'json' require 'open3' module SimCtl class Executor class << self def execute(command) command = command.flatten.join(' ') Open3.popen3(command) do |stdin, stdout, stderr, result| output = stdout.read raise StandardError.new(output) if result.value.to_i > 0 return unless block_given? if looks_like_json?(output) yield JSON.parse(output) else yield output.chomp end end end private def looks_like_json?(output) output.start_with?('[') || output.start_with?('{') end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
simctl-1.4.1 | lib/simctl/executor.rb |
simctl-1.4.0 | lib/simctl/executor.rb |
simctl-1.3.1 | lib/simctl/executor.rb |
simctl-1.3.0 | lib/simctl/executor.rb |