Module: Terraspace::Util::Sh

Included in:
Terraspace::Util
Defined in:
lib/terraspace/util/sh.rb

Instance Method Summary collapse

Instance Method Details

#sh(command, options = {}) ⇒ Object

requires @mod to be set



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/terraspace/util/sh.rb', line 4

def sh(command, options={})
  exit_on_fail = options[:exit_on_fail].nil? ? true : options[:exit_on_fail]
  env = options[:env] || {}
  env.stringify_keys!

  logger.info "=> #{command}"
  return if ENV['TS_TEST']

  success = system(env, command, chdir: @mod.cache_dir)
  unless success
    logger.info "Error running command: #{command}".color(:red)
    exit $?.exitstatus if exit_on_fail
  end
end