@@ -30,21 +30,31 @@ def self.which(cmd)
3030 nil
3131 end
3232
33+ # Execute a shell command and capture stdout, stderr, and status
34+ #
35+ # @see Process.spawn
36+ # @see https://docs.ruby-lang.org/en/2.0.0/Process.html#method-c-spawn
37+ # @return [Hash] with keys "stdout" (String), "stderr" (String), and "success" (bool)
3338 def self . run_and_capture ( *args , **kwargs )
3439 stdout , stderr , status = Open3 . capture3 ( *args , **kwargs )
3540 { out : stdout , err : stderr , success : status . exitstatus . zero? }
3641 end
3742
38- def self . merge_capture_results ( args )
39- result = { out : "" , err : "" , success : true }
40- args . each do |a |
41- result [ :out ] = result [ :out ] + a [ :out ]
42- result [ :err ] = result [ :err ] + a [ :err ]
43- result [ :success ] = a [ :success ] unless a [ :success ]
44- end
45- result
43+ # Merge multiple capture results into one aggregate value
44+ #
45+ # @param args [Array] Array of hashes from `run_and_capture`
46+ # @return [Hash] with keys "stdout" (String), "stderr" (String), and "success" (bool)
47+ def self . merge_capture_results ( *args )
48+ {
49+ out : args . map { |a | a [ :out ] } . join ( ) ,
50+ err : args . map { |a | a [ :err ] } . join ( ) ,
51+ success : args . all? { |a | a [ :success ] }
52+ }
4653 end
4754
55+ # Execute a shell command
56+ #
57+ # @see system
4858 def self . run_and_output ( *args , **kwargs )
4959 system ( *args , **kwargs )
5060 end
0 commit comments