class XcodeArchiveCache::Shell::Executor

Public Instance Methods

execute(command, print_command = false) click to toggle source

@param [String] command @param [Boolean] print_command

@return [Boolean] true if command succeeded and returned 0, false otherwise

# File lib/shell/executor.rb, line 26
def execute(command, print_command = false)
  actual_command = extend_for_pipefail(command, print_command)
  result = system actual_command

  return false if result == nil
  result
end
execute_for_output(command, print_command = false) click to toggle source

@param [String] command @param [Boolean] print_command

@return [String]

# File lib/shell/executor.rb, line 10
def execute_for_output(command, print_command = false)
  actual_command = extend_for_pipefail(command, print_command)
  output, status = Open3.capture2e(actual_command)

  if status.exitstatus != 0
    raise XcodeArchiveCache::Informative, "#{command}\nexecution failed\n#{output}"
  end

  output
end
execute_with_env(command, env) click to toggle source

@param [String] command @param [Hash] env

@return [Boolean] true if command succeeded and returned 0, false otherwise

# File lib/shell/executor.rb, line 39
def execute_with_env(command, env)
  result = system(env, "set -x && '#{command}'")

  return false if result == nil
  result
end

Private Instance Methods

contains_pipes?(command) click to toggle source

@param [String] command

@return [Boolean]

# File lib/shell/executor.rb, line 63
def contains_pipes?(command)
  command.include?("|")
end
extend_for_pipefail(command, print_command) click to toggle source

@param [String] command @param [Boolean] print_command

@return [String]

# File lib/shell/executor.rb, line 53
def extend_for_pipefail(command, print_command)
  return command unless contains_pipes?(command)

  "set #{pipefail_flags(print_command: print_command)} && #{command}"
end
pipefail_flags(print_command) click to toggle source

@param [Boolean] print_command

@return [String]

# File lib/shell/executor.rb, line 71
def pipefail_flags(print_command)
  flags = ["e", "o pipefail"]
  if print_command
    flags.insert(1, "x")
  end

  "-" + flags.join(" -")
end