class FastlaneCore::Shell

Shell is the terminal output of things For documentation for each of the methods open `interface.rb`

Public Instance Methods

command(message) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 67
def command(message)
  log.info("$ #{message}".cyan)
end
command_output(message) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 71
def command_output(message)
  actual = (encode_as_utf_8_if_possible(message).split("\r").last || "") # as clearing the line will remove the `>` and the time stamp
  actual.split("\n").each do |msg|
    if FastlaneCore::Env.truthy?("FASTLANE_DISABLE_OUTPUT_FORMAT")
      log.info(msg)
    else
      prefix = msg.include?("▸") ? "" : "▸ "
      log.info(prefix + "" + msg.magenta)
    end
  end
end
confirm(message) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 133
def confirm(message)
  verify_interactive!(message)
  agree("#{format_string}#{message.to_s.yellow} (y/n)", true)
end
content_error(content, error_line) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 100
def content_error(content, error_line)
  error_line = error_line.to_i
  return unless error_line > 0

  contents = content.split(/\r?\n/).map(&:chomp)

  start_line = error_line - 2 < 1 ? 1 : error_line - 2
  end_line = error_line + 2 < contents.length ? error_line + 2 : contents.length

  Range.new(start_line, end_line).each do |line|
    str = line == error_line ? " => " : "    "
    str << line.to_s.rjust(Math.log10(end_line) + 1)
    str << ":\t#{contents[line - 1]}"
    error(str)
  end
end
deprecated(message) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 63
def deprecated(message)
  log.error(message.to_s.deprecated)
end
error(message) click to toggle source

@!group Messaging: show text to the user

# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 47
def error(message)
  log.error(message.to_s.red)
end
format_string(datetime = Time.now, severity = "") click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 32
def format_string(datetime = Time.now, severity = "")
  timezone_string = !FastlaneCore::Env.truthy?('FASTLANE_SHOW_TIMEZONE') ? '' : ' %z'
  if FastlaneCore::Globals.verbose?
    return "#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%2N' + timezone_string)}]: "
  elsif FastlaneCore::Env.truthy?("FASTLANE_HIDE_TIMESTAMP")
    return ""
  else
    return "[#{datetime.strftime('%H:%M:%S' + timezone_string)}]: "
  end
end
header(message) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 87
def header(message)
  format = format_string
  if message.length + 8 < TTY::Screen.width - format.length
    message = "--- #{message} ---"
    i = message.length
  else
    i = TTY::Screen.width - format.length
  end
  success("-" * i)
  success(message)
  success("-" * i)
end
important(message) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 51
def important(message)
  log.warn(message.to_s.yellow)
end
input(message) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 128
def input(message)
  verify_interactive!(message)
  ask("#{format_string}#{message.to_s.yellow}").to_s.strip
end
interactive?() click to toggle source

@!group Errors: Inputs

# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 121
def interactive?
  interactive = true
  interactive = false if $stdout.isatty == false
  interactive = false if Helper.ci?
  return interactive
end
log() click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 13
def log
  return @log if @log

  $stdout.sync = true

  if Helper.test? && !ENV.key?('DEBUG')
    $stdout.puts("Logging disabled while running tests. Force them by setting the DEBUG environment variable")
    @log ||= Logger.new(nil) # don't show any logs when running tests
  else
    @log ||= Logger.new($stdout)
  end

  @log.formatter = proc do |severity, datetime, progname, msg|
    "#{format_string(datetime, severity)}#{msg}\n"
  end

  @log
end
message(message) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 59
def message(message)
  log.info(message.to_s)
end
password(message) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 145
def password(message)
  verify_interactive!(message)

  ask("#{format_string}#{message.to_s.yellow}") do |q|
    q.whitespace = :chomp
    q.echo = "*"
  end
end
select(message, options) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 138
def select(message, options)
  verify_interactive!(message)

  important(message)
  choose(*options)
end
success(message) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 55
def success(message)
  log.info(message.to_s.green)
end
verbose(message) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 83
def verbose(message)
  log.debug(message.to_s) if FastlaneCore::Globals.verbose?
end

Private Instance Methods

encode_as_utf_8_if_possible(message) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 156
def encode_as_utf_8_if_possible(message)
  return message if message.valid_encoding?

  # genstrings outputs UTF-16, so we should try to use this encoding if it turns out to be valid
  test_message = message.dup
  return message.encode(Encoding::UTF_8, Encoding::UTF_16) if test_message.force_encoding(Encoding::UTF_16).valid_encoding?

  # replace any invalid with empty string
  message.encode(Encoding::UTF_8, invalid: :replace)
end
verify_interactive!(message) click to toggle source
# File fastlane_core/lib/fastlane_core/ui/implementations/shell.rb, line 167
def verify_interactive!(message)
  return if interactive?
  important(message)
  crash!("Could not retrieve response as fastlane runs in non-interactive mode")
end