class Maintainer::CommandRunner
Public Class Methods
_execute(command: nil, error:nil)
click to toggle source
# File lib/maintainer_core/commandRunner.rb, line 69 def _execute(command: nil, error:nil) print_all = true prefix ||= {} output = [] Writer.write(message: "#{command}") begin status = Maintainer::MaintainerPty.spawn(command) do |command_stdout, command_stdin, pid| command_stdout.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 Writer.write(message: "#{line}") end end rescue => ex # FastlanePty adds exit_status on to StandardError so every error will have a status code status = ex.exit_status # 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) if error error.call(o, nil) else raise ex end end # Exit status for build command, should be 0 if build succeeded if status != 0 o = output.join("\n") puts(o) Writer.write(message: ("Exit status: #{status}")) if error error.call(o, status) else Writer.write(message: ("Exit status: #{status}")) end end return output.join("\n") end
execute(command: nil, error:nil)
click to toggle source
# File lib/maintainer_core/commandRunner.rb, line 57 def execute(command: nil, error:nil) output = [] if command.is_a? String output << _execute(command: command, error: error) else command.command!.each do |item| output << _execute(command: item, error: error) end end return output.join("\n") end
execute_sudo(command: nil)
click to toggle source
# File lib/maintainer_core/commandRunner.rb, line 53 def execute_sudo(command: nil) system("sudo #{command}") end