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


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

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

#command_output(message) ⇒ Object


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

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


133
134
135
136
# 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) ⇒ Object


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# 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) ⇒ Object


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

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

#error(message) ⇒ Object


47
48
49
# 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 = "") ⇒ Object


32
33
34
35
36
37
38
39
40
41
# 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) ⇒ Object


87
88
89
90
91
92
93
94
95
96
97
98
# 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) ⇒ Object


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

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

#input(message) ⇒ Object


128
129
130
131
# 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?Boolean

Returns:


121
122
123
124
125
126
# 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

#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


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

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

#password(message) ⇒ Object


145
146
147
148
149
# 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}") { |q| q.echo = "*" }
end

#select(message, options) ⇒ Object


138
139
140
141
142
143
# 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) ⇒ Object


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

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

#verbose(message) ⇒ Object


83
84
85
# 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