Sha256: b8c5cfd91db261097238f5df9f0e025981fd0e5e69b1e20e410438906cfc25c2

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

# typed: strict
# frozen_string_literal: true

require "sorbet-runtime"
require "pathname"

module Spoom
  extend T::Sig

  SPOOM_PATH = T.let((Pathname.new(__FILE__) / ".." / "..").to_s, String)

  class Error < StandardError; end

  class ExecResult < T::Struct
    const :out, String
    const :err, String
    const :status, T::Boolean
    const :exit_code, Integer
  end

  sig do
    params(
      cmd: String,
      arg: String,
      path: String,
      capture_err: T::Boolean
    ).returns(ExecResult)
  end
  def self.exec(cmd, *arg, path: '.', capture_err: false)
    if capture_err
      stdout, stderr, status = T.unsafe(Open3).capture3([cmd, *arg].join(" "), chdir: path)
      ExecResult.new(
        out: stdout,
        err: stderr,
        status: status.success?,
        exit_code: status.exitstatus
      )
    else
      stdout, status = T.unsafe(Open3).capture2([cmd, *arg].join(" "), chdir: path)
      ExecResult.new(
        out: stdout,
        err: "",
        status: status.success?,
        exit_code: status.exitstatus
      )
    end
  end
end

require "spoom/colors"
require "spoom/sorbet"
require "spoom/cli"
require "spoom/version"

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spoom-1.1.11 lib/spoom.rb
spoom-1.1.10 lib/spoom.rb
spoom-1.1.9 lib/spoom.rb