Class: Schlib::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/schlib/command.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger = nil) ⇒ Command

Returns a new instance of Command.



7
8
9
# File 'lib/schlib/command.rb', line 7

def initialize(logger = nil)
  @logger = logger
end

Instance Method Details

#run(command, approve_exitcode: false) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/schlib/command.rb', line 11

def run(command, approve_exitcode: false)
  logger&.debug command
  output = `#{command} 2>&1`
  logger&.debug output
  if approve_exitcode && !$CHILD_STATUS.success?
    raise ScriptError, 'COMMAND FAILED!'
  end
  output
end