module Scallop::Executor

Executes command and returns result.

Public Class Methods

build_result(capture3, timing) click to toggle source
# File lib/scallop/executor.rb, line 25
def self.build_result(capture3, timing)
  stdout, stderr, status = capture3

  Result
    .new(
      stdout: stdout.to_s.strip,
      stderr: stderr.to_s.strip,
      status: status,
      timing: timing,
    )
    .freeze
end
measure() { || ... } click to toggle source
# File lib/scallop/executor.rb, line 19
def self.measure
  result = nil
  timing = Benchmark.measure { result = yield }
  [result, timing]
end
run(command, args = {}) click to toggle source
# File lib/scallop/executor.rb, line 6
def self.run(command, args = {})
  capture3, timing = measure do
    Open3.capture3(command, args)
  end
  build_result(capture3, timing)
end
run!(command, args = {}) click to toggle source
# File lib/scallop/executor.rb, line 13
def self.run!(command, args = {})
  run(command, args).tap do |result|
    raise Errors::CommandFailed.new(result.stderr, result) unless result.success?
  end
end