module Bindep::Helpers

Public Class Methods

cmd(command, stdin = nil, raise_on_error = true) click to toggle source

Run a command, supply stdin and capture stdout and stderr.

# File lib/bindep/helpers.rb, line 4
def self.cmd(command, stdin = nil, raise_on_error = true)
  stdout, stderr, status = Open3.capture3 command, stdin_data: stdin, binmode: true

  if raise_on_error && (status.exitstatus != 0 || stderr =~ /error/i)
    raise RuntimeError, "Command '#{command}' returned status #{status.exitstatus}"
  end

  [ stdout, stderr, status.exitstatus ]
end
cmd_interactive(command, raise_on_error = true) click to toggle source

Run a command interactively, return exit status

# File lib/bindep/helpers.rb, line 15
def self.cmd_interactive(command, raise_on_error = true)
  system command

  if raise_on_error && !$?.exitstatus.zero?
    raise RuntimeError, "Command '#{command}' returned status #{$?.exitstatus}"
  end

  $?.exitstatus
end
command_exists?(cmd) click to toggle source

Check if a shell command exists (using “which”).

# File lib/bindep/helpers.rb, line 26
def self.command_exists?(cmd)
  _, _, status = Helpers.cmd "which #{cmd.strip}", nil, false
  status.zero?
end
which_test() click to toggle source

Check if “which” command is available and works correctly.

# File lib/bindep/helpers.rb, line 32
def self.which_test
  command_exists?("which") && !command_exists?("foo_bar_command_does_not_exist")
end