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) ⇒ String
All the output as string.
Class Method Details
.execute(command: nil, print_all: false, print_command: true, error: nil) ⇒ String
Returns All the output as string.
10 11 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 |
# File 'lib/fastlane_core/command_executor.rb', line 10 def execute(command: nil, print_all: false, print_command: true, error: nil) print_all = true if $verbose output = [] command = command.join(" ") Helper.log.info command.yellow.strip if print_command puts "\n-----".cyan if print_all last_length = 0 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 current_length = line.length spaces = [last_length - current_length, 0].max print((line + " " * spaces + "\r").cyan) 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) 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) end end |