Module: Rap::Utils

Included in:
Declarations
Defined in:
lib/rap/utils.rb

Instance Method Summary collapse

Instance Method Details

#sh(*cmd) ⇒ Object

Run the system command cmd, passing the result to the block, if given. Raises an error if the command fails. Uses the same semantics as Kernel::exec and Kernel::system.

Based on FileUtils#sh from Rake.



8
9
10
11
12
13
14
15
16
# File 'lib/rap/utils.rb', line 8

def sh(*cmd) # :yields: ok, status
  ok = system(*cmd)

  if block_given?
    yield(ok, $?)
  else
    ok or raise "Command failed with status (#{$?.exitstatus}): [#{cmd.join(' ')}]"
  end
end