Class: Appear::Runner
- Inherits:
-
Service
- Object
- BaseService
- Service
- Appear::Runner
- Defined in:
- lib/appear/runner.rb
Overview
Service for executing commands. Better than a mixin everywhere.
Direct Known Subclasses
Instance Method Summary collapse
-
#run(command, opts = {}) ⇒ String
Run a command.
Methods inherited from BaseService
delegate, #initialize, require_service, required_services
Constructor Details
This class inherits a constructor from Appear::BaseService
Instance Method Details
#run(command, opts = {}) ⇒ String
Run a command. Throws an exception if the command fails. Command can either be a string, or an array of command name and parameters. Returns the combinded STDERR and STDOUT of the command.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/appear/runner.rb', line 33 def run(command, opts = {}) allow_failure = opts[:allow_failure] || false start = Time.new if command.is_a? Array output, status = Open3.capture2e(*command) else output, status = Open3.capture2e(command) end finish = Time.new log("Runner: ran #{command.inspect} in #{finish - start}s") if !status.success? && !allow_failure raise ExecutionFailure.new(command, output) end output end |