Class: Rbs::Src::CommandRunner
- Inherits:
-
Object
- Object
- Rbs::Src::CommandRunner
- Defined in:
- lib/rbs/src/command_runner.rb
Instance Attribute Summary collapse
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #execute!(*command, chdir: Pathname.pwd) ⇒ Object
-
#initialize(stdout:) ⇒ CommandRunner
constructor
A new instance of CommandRunner.
- #push(message) ⇒ Object
- #puts(message) ⇒ Object
- #query!(*command, chdir: Pathname.pwd) ⇒ Object
- #query?(*command, chdir: Pathname.pwd) ⇒ Boolean
Constructor Details
#initialize(stdout:) ⇒ CommandRunner
Returns a new instance of CommandRunner.
6 7 8 9 |
# File 'lib/rbs/src/command_runner.rb', line 6 def initialize(stdout:) @stdout = stdout @level = 0 end |
Instance Attribute Details
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
4 5 6 |
# File 'lib/rbs/src/command_runner.rb', line 4 def stdout @stdout end |
Instance Method Details
#execute!(*command, chdir: Pathname.pwd) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rbs/src/command_runner.rb', line 26 def execute!(*command, chdir: Pathname.pwd) # @type var out: String # @type var status: Process::Status out, status = Open3.capture2e(*command, chdir: chdir) unless status.success? puts "đ¨ Command failed: #{command.inspect} in #{chdir}..." out.each_line do |line| puts "| #{line}" end raise status.inspect end end |
#push(message) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/rbs/src/command_runner.rb', line 16 def push() puts "âŠī¸ #{}" begin @level += 1 yield ensure @level -= 1 end end |
#puts(message) ⇒ Object
11 12 13 14 |
# File 'lib/rbs/src/command_runner.rb', line 11 def puts() prefix = " " * @level stdout.puts "#{prefix}#{}" end |
#query!(*command, chdir: Pathname.pwd) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rbs/src/command_runner.rb', line 52 def query!(*command, chdir: Pathname.pwd) # @type var out: String # @type var status: Process::Status out, status = Open3.capture2e(*command, chdir: chdir) unless status.success? puts "đ¨ Command failed: #{command.inspect} in #{chdir}..." out.each_line do |line| puts "| #{line}" end raise status.inspect end out end |
#query?(*command, chdir: Pathname.pwd) ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rbs/src/command_runner.rb', line 41 def query?(*command, chdir: Pathname.pwd) # @type var out: String # @type var status: Process::Status out, status = Open3.capture2e(*command, chdir: chdir) if status.success? out end end |