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
- .clear_display ⇒ Object
-
.execute(command: nil, print_all: false, print_command: true, error: nil, prefix: nil, loading: nil) ⇒ String
All the output as string.
Class Method Details
.clear_display ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/fastlane_core/command_executor.rb', line 68 def clear_display return if Helper.ci? if Helper.iterm? system("clear") end end |
.execute(command: nil, print_all: false, print_command: true, error: nil, prefix: nil, loading: nil) ⇒ 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 |
# 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) Helper.log.info command.yellow.strip if print_command if print_all and loading # this is only used to show the "Loading text"... clear_display puts loading.cyan 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 # The actual output here, first clear and then print out 3 lines clear_display puts line end Process.wait(pid) clear_display 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 |