Sha256: 7b199cf6edd7153a881d1ef8606dcab00566c844b2c562a5d78145458d3bcbc5

Contents?: true

Size: 1.88 KB

Versions: 13

Compression:

Stored size: 1.88 KB

Contents

module FastlaneCore
  # Executes commands and takes care of error handling and more
  class CommandExecutor
    class << self
      # @param command [String] The command to be executed
      # @param print_all [Boolean] Do we want to print out the command output while running?
      # @param print_command [Boolean] Should we print the command that's being executed
      # @param error [Block] A block that's called if an error occurs
      # @return [String] All the output as string
      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
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
fastlane_core-0.19.0 lib/fastlane_core/command_executor.rb
fastlane_core-0.18.2 lib/fastlane_core/command_executor.rb
fastlane_core-0.18.1 lib/fastlane_core/command_executor.rb
fastlane_core-0.18.0 lib/fastlane_core/command_executor.rb
fastlane_core-0.17.1 lib/fastlane_core/command_executor.rb
fastlane_core-0.17.0 lib/fastlane_core/command_executor.rb
fastlane_core-0.16.2 lib/fastlane_core/command_executor.rb
fastlane_core-0.16.1 lib/fastlane_core/command_executor.rb
fastlane_core-0.16.0 lib/fastlane_core/command_executor.rb
fastlane_core-0.15.3 lib/fastlane_core/command_executor.rb
fastlane_core-0.15.2 lib/fastlane_core/command_executor.rb
fastlane_core-0.15.1 lib/fastlane_core/command_executor.rb
fastlane_core-0.15.0 lib/fastlane_core/command_executor.rb