@@ -30,21 +30,31 @@ def self.which(cmd)
30
30
nil
31
31
end
32
32
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)
33
38
def self . run_and_capture ( *args , **kwargs )
34
39
stdout , stderr , status = Open3 . capture3 ( *args , **kwargs )
35
40
{ out : stdout , err : stderr , success : status . exitstatus . zero? }
36
41
end
37
42
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
+ }
46
53
end
47
54
55
+ # Execute a shell command
56
+ #
57
+ # @see system
48
58
def self . run_and_output ( *args , **kwargs )
49
59
system ( *args , **kwargs )
50
60
end
0 commit comments