Class: FastlaneCore::CommandExecutor
- Inherits:
-
Object
- Object
- FastlaneCore::CommandExecutor
- Defined in:
- lib/fastlane_core/command_executor.rb
Overview
Executes commands and takes care of error handling and more
Class Method Summary collapse
-
.execute(command: nil, print_all: false, print_command: true, error: nil, prefix: nil, loading: nil) ⇒ String
All the output as string.
Class Method Details
.execute(command: nil, print_all: false, print_command: true, error: nil, prefix: nil, loading: nil) ⇒ String
Returns All the output as string.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fastlane_core/command_executor.rb', line 12 def execute(command: nil, print_all: false, print_command: true, error: nil, prefix: nil, loading: nil) print_all = true if $verbose prefix ||= {} output = [] command = command.join(" ") if command.kind_of?(Array) UI.command(command) if print_command if print_all and loading # this is only used to show the "Loading text"... UI.command_output(loading) end begin PTY.spawn(command) do |stdin, stdout, pid| stdin.each do |l| line = l.strip # strip so that \n gets removed output << line next unless print_all # Prefix the current line with a string prefix.each do |element| line = element[:prefix] + line if element[:block] && element[:block].call(line) end UI.command_output(line) end Process.wait(pid) end rescue => ex # This could happen when the environment is wrong: # > invalid byte sequence in US-ASCII (ArgumentError) output << ex.to_s o = output.join("\n") puts o error.call(o, nil) end # Exit status for build command, should be 0 if build succeeded status = $?.exitstatus if status != 0 o = output.join("\n") puts o # the user has the right to see the raw output UI.error "Exit status: #{status}" error.call(o, status) end return output.join("\n") end |