Class: Exercism::Rb::CommandRunner
- Inherits:
-
Object
- Object
- Exercism::Rb::CommandRunner
- Defined in:
- lib/exercism/rb/command_runner.rb
Instance Method Summary collapse
-
#initialize(ui: UI.new) ⇒ CommandRunner
constructor
A new instance of CommandRunner.
- #run(*args, chdir: nil) ⇒ Object
Constructor Details
#initialize(ui: UI.new) ⇒ CommandRunner
Returns a new instance of CommandRunner.
8 9 10 |
# File 'lib/exercism/rb/command_runner.rb', line 8 def initialize(ui: UI.new) @ui = ui end |
Instance Method Details
#run(*args, chdir: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/exercism/rb/command_runner.rb', line 12 def run(*args, chdir: nil) printable = Shellwords.join(args) printable = "cd #{Shellwords.escape(chdir)} && #{printable}" if chdir @ui.command("$ #{printable}") ok = if chdir Dir.chdir(chdir) { system(*args) } else system(*args) end raise Error, "Command failed: #{Shellwords.join(args)}" unless ok true end |