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 61 62 63 64 65 66 67 68 69 70 |
# 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(" ") Helper.log.info command.yellow.strip if print_command puts "\n-----".cyan if print_all if loading print(loading.cyan + "\r") last_length = loading.length else last_length = 0 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 line = line.cyan # Prefix the current line with a string prefix.each do |element| line = element[:prefix] + line if element[:block] && element[:block].call(line) end current_length = line.length spaces = [last_length - current_length, 0].max print(line + " " * spaces + "\r") last_length = current_length end Process.wait(pid) puts "-----\n".cyan if print_all 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 Helper.log.info "Exit status: #{status}" error.call(o, status) end return output.join("\n") end |