Class: Gemchain::Executor::Runner
- Inherits:
-
Object
- Object
- Gemchain::Executor::Runner
- Defined in:
- lib/gemchain/executor.rb
Overview
Real command runner: executes via Open3, raises ExecutionError with output context on any non-zero exit.
Instance Method Summary collapse
- #run(command, chdir: nil) ⇒ Object
-
#success?(command, chdir: nil) ⇒ Boolean
Runs a command and reports success without raising.
Instance Method Details
#run(command, chdir: nil) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/gemchain/executor.rb', line 19 def run(command, chdir: nil) out, err, status = Open3.capture3(*command, chdir: chdir) return if status.success? detail = err.lines.first(5).join.strip detail = out.lines.first(5).join.strip if detail.empty? raise ExecutionError, "Command failed: #{command.join(' ')}#{detail.empty? ? '' : "\n#{detail}"}" end |
#success?(command, chdir: nil) ⇒ Boolean
Runs a command and reports success without raising. Used for conditional checks (e.g. "are there staged changes?").
30 31 32 33 |
# File 'lib/gemchain/executor.rb', line 30 def success?(command, chdir: nil) _out, _err, status = Open3.capture3(*command, chdir: chdir) status.success? end |