Class: FastlaneCore::Shell

Inherits:
Interface show all
Defined in:
fastlane_core/lib/fastlane_core/ui/implementations/shell.rb

Overview

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

Messaging: show text to the user collapse

Errors: Inputs collapse

Instance Method Summary collapse

Methods inherited from Interface

#abort_with_message!, #build_failure!, #crash!, #not_implemented, #shell_error!, #test_failure!, #to_s, #user_error!

Instance Method Details

#command(message) ⇒ Object



66
67
68
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 66

def command(message)
  log.info("$ #{message}".cyan)
end

#command_output(message) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 70

def command_output(message)
  actual = (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) ⇒ Object



132
133
134
135
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 132

def confirm(message)
  verify_interactive!(message)
  agree("#{format_string}#{message.to_s.yellow} (y/n)", true)
end

#content_error(content, error_line) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 99

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) ⇒ Object



62
63
64
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 62

def deprecated(message)
  log.error(message.to_s.deprecated)
end

#error(message) ⇒ Object



46
47
48
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 46

def error(message)
  log.error(message.to_s.red)
end

#format_string(datetime = Time.now, severity = "") ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 32

def format_string(datetime = Time.now, severity = "")
  if FastlaneCore::Globals.verbose?
    return "#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%2N')}]: "
  elsif FastlaneCore::Env.truthy?("FASTLANE_HIDE_TIMESTAMP")
    return ""
  else
    return "[#{datetime.strftime('%H:%M:%S')}]: "
  end
end

#header(message) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 86

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) ⇒ Object



50
51
52
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 50

def important(message)
  log.warn(message.to_s.yellow)
end

#input(message) ⇒ Object



127
128
129
130
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 127

def input(message)
  verify_interactive!(message)
  ask("#{format_string}#{message.to_s.yellow}").to_s.strip
end

#interactive?Boolean

Returns:



120
121
122
123
124
125
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 120

def interactive?
  interactive = true
  interactive = false if $stdout.isatty == false
  interactive = false if Helper.ci?
  return interactive
end

#logObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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) ⇒ Object



58
59
60
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 58

def message(message)
  log.info(message.to_s)
end

#password(message) ⇒ Object



144
145
146
147
148
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 144

def password(message)
  verify_interactive!(message)

  ask("#{format_string}#{message.to_s.yellow}") { |q| q.echo = "*" }
end

#select(message, options) ⇒ Object



137
138
139
140
141
142
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 137

def select(message, options)
  verify_interactive!(message)

  important(message)
  choose(*options)
end

#success(message) ⇒ Object



54
55
56
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 54

def success(message)
  log.info(message.to_s.green)
end

#verbose(message) ⇒ Object



82
83
84
# File 'fastlane_core/lib/fastlane_core/ui/implementations/shell.rb', line 82

def verbose(message)
  log.debug(message.to_s) if FastlaneCore::Globals.verbose?
end