Module: Bulldog::Util

Included in:
Bulldog
Defined in:
lib/bulldog/util.rb

Defined Under Namespace

Modules: Shellwords

Instance Method Summary collapse

Instance Method Details

#run(*command) ⇒ Object

Run the given command, logging everything obsessively.

Return the output if the command is successful, nil otherwise. If an :expect_status option is given, any status codes in the list are considered successful.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bulldog/util.rb', line 10

def run(*command)
  options = command.last.is_a?(Hash) ? command.pop : {}
  command.map!{|x| x.to_s}
  command = Shellwords.join(command) + ' 2>&1'
  Bulldog.logger.info("[Bulldog] Running: #{command}") if Bulldog.logger
  output = `#{command}`
  status = $?.exitstatus
  if Bulldog.logger
    Bulldog.logger.info("[Bulldog] Output: #{output}")
    Bulldog.logger.info("[Bulldog] Status: #{status}")
  end
  expected_statuses = options[:expect_status] || [0]
  expected_statuses.include?(status) ? output : nil
end