Sha256: d3a27bc97fddaf95b5153a316e58b8d9c08d6b170f0e008320ac0c87f87c055a

Contents?: true

Size: 676 Bytes

Versions: 1

Compression:

Stored size: 676 Bytes

Contents

require 'open3'

module InvocaGems::ShellCommand
  def self.included(klass)
    klass.send(:extend, InvocaGems::ShellCommand)
  end

  # Returns the command output, stripped
  # Or nil if command failed
  Response = Struct.new(:stdout, :stderr, :code)
  def shell_command(command:, path: '.', presenter:, raise_errors: true)
    presenter.set_subtask "cd #{path}; #{command}"
    r = Response.new(*Open3.capture3("cd #{path}; #{command}"))
    if r.code && r.code.success?
      r.stdout.strip
    else
      if raise_errors
        presenter.stop_with_message "cd #{path}; #{command}: returned error #{r.code.exitstatus}: #{r.stdout}\n#{r.stderr}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
invoca_gems-0.1.0 lib/invoca_gems/shell_command.rb