pantograph 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +1 -0
  3. data/LICENSE +21 -0
  4. data/README.md +197 -0
  5. data/bin/bin-proxy +19 -0
  6. data/bin/pantograph +23 -0
  7. data/pantograph/README.md +11 -0
  8. data/pantograph/lib/assets/ActionDetails.md.erb +106 -0
  9. data/pantograph/lib/assets/Actions.md.erb +43 -0
  10. data/pantograph/lib/assets/DefaultPantfileTemplate +20 -0
  11. data/pantograph/lib/assets/completions/completion.bash +23 -0
  12. data/pantograph/lib/assets/completions/completion.fish +39 -0
  13. data/pantograph/lib/assets/completions/completion.sh +12 -0
  14. data/pantograph/lib/assets/completions/completion.zsh +23 -0
  15. data/pantograph/lib/assets/custom_action_template.rb +80 -0
  16. data/pantograph/lib/assets/report_template.xml.erb +15 -0
  17. data/pantograph/lib/pantograph/action.rb +194 -0
  18. data/pantograph/lib/pantograph/action_collector.rb +35 -0
  19. data/pantograph/lib/pantograph/actions/README.md +3 -0
  20. data/pantograph/lib/pantograph/actions/actions_helper.rb +166 -0
  21. data/pantograph/lib/pantograph/actions/add_extra_platforms.rb +45 -0
  22. data/pantograph/lib/pantograph/actions/artifactory.rb +157 -0
  23. data/pantograph/lib/pantograph/actions/bundle_install.rb +156 -0
  24. data/pantograph/lib/pantograph/actions/changelog_from_git_commits.rb +197 -0
  25. data/pantograph/lib/pantograph/actions/clipboard.rb +52 -0
  26. data/pantograph/lib/pantograph/actions/cloc.rb +89 -0
  27. data/pantograph/lib/pantograph/actions/create_pull_request.rb +190 -0
  28. data/pantograph/lib/pantograph/actions/danger.rb +131 -0
  29. data/pantograph/lib/pantograph/actions/debug.rb +32 -0
  30. data/pantograph/lib/pantograph/actions/default_platform.rb +47 -0
  31. data/pantograph/lib/pantograph/actions/download.rb +76 -0
  32. data/pantograph/lib/pantograph/actions/echo.rb +14 -0
  33. data/pantograph/lib/pantograph/actions/ensure_bundle_exec.rb +59 -0
  34. data/pantograph/lib/pantograph/actions/ensure_env_vars.rb +58 -0
  35. data/pantograph/lib/pantograph/actions/ensure_git_branch.rb +69 -0
  36. data/pantograph/lib/pantograph/actions/ensure_git_status_clean.rb +81 -0
  37. data/pantograph/lib/pantograph/actions/erb.rb +88 -0
  38. data/pantograph/lib/pantograph/actions/get_build_number_repository.rb +120 -0
  39. data/pantograph/lib/pantograph/actions/get_github_release.rb +163 -0
  40. data/pantograph/lib/pantograph/actions/git_add.rb +93 -0
  41. data/pantograph/lib/pantograph/actions/git_branch.rb +58 -0
  42. data/pantograph/lib/pantograph/actions/git_commit.rb +80 -0
  43. data/pantograph/lib/pantograph/actions/git_pull.rb +53 -0
  44. data/pantograph/lib/pantograph/actions/git_submodule_update.rb +52 -0
  45. data/pantograph/lib/pantograph/actions/git_tag_exists.rb +74 -0
  46. data/pantograph/lib/pantograph/actions/github_api.rb +262 -0
  47. data/pantograph/lib/pantograph/actions/gradle.rb +278 -0
  48. data/pantograph/lib/pantograph/actions/import.rb +49 -0
  49. data/pantograph/lib/pantograph/actions/import_from_git.rb +71 -0
  50. data/pantograph/lib/pantograph/actions/is_ci.rb +51 -0
  51. data/pantograph/lib/pantograph/actions/jira.rb +115 -0
  52. data/pantograph/lib/pantograph/actions/lane_context.rb +60 -0
  53. data/pantograph/lib/pantograph/actions/last_git_commit.rb +58 -0
  54. data/pantograph/lib/pantograph/actions/last_git_tag.rb +51 -0
  55. data/pantograph/lib/pantograph/actions/make_changelog_from_jenkins.rb +81 -0
  56. data/pantograph/lib/pantograph/actions/min_pantograph_version.rb +57 -0
  57. data/pantograph/lib/pantograph/actions/nexus_upload.rb +230 -0
  58. data/pantograph/lib/pantograph/actions/notification.rb +75 -0
  59. data/pantograph/lib/pantograph/actions/number_of_commits.rb +75 -0
  60. data/pantograph/lib/pantograph/actions/opt_out_usage.rb +40 -0
  61. data/pantograph/lib/pantograph/actions/pantograph_version.rb +15 -0
  62. data/pantograph/lib/pantograph/actions/println.rb +14 -0
  63. data/pantograph/lib/pantograph/actions/prompt.rb +119 -0
  64. data/pantograph/lib/pantograph/actions/push_git_tags.rb +76 -0
  65. data/pantograph/lib/pantograph/actions/push_to_git_remote.rb +127 -0
  66. data/pantograph/lib/pantograph/actions/puts.rb +68 -0
  67. data/pantograph/lib/pantograph/actions/reset_git_repo.rb +121 -0
  68. data/pantograph/lib/pantograph/actions/rocket.rb +83 -0
  69. data/pantograph/lib/pantograph/actions/rsync.rb +74 -0
  70. data/pantograph/lib/pantograph/actions/ruby_version.rb +56 -0
  71. data/pantograph/lib/pantograph/actions/say.rb +56 -0
  72. data/pantograph/lib/pantograph/actions/scp.rb +114 -0
  73. data/pantograph/lib/pantograph/actions/set_github_release.rb +274 -0
  74. data/pantograph/lib/pantograph/actions/sh.rb +71 -0
  75. data/pantograph/lib/pantograph/actions/skip_docs.rb +52 -0
  76. data/pantograph/lib/pantograph/actions/slack.rb +288 -0
  77. data/pantograph/lib/pantograph/actions/sonar.rb +156 -0
  78. data/pantograph/lib/pantograph/actions/ssh.rb +162 -0
  79. data/pantograph/lib/pantograph/actions/twitter.rb +89 -0
  80. data/pantograph/lib/pantograph/actions/update_pantograph.rb +177 -0
  81. data/pantograph/lib/pantograph/actions/zip.rb +120 -0
  82. data/pantograph/lib/pantograph/auto_complete.rb +82 -0
  83. data/pantograph/lib/pantograph/boolean.rb +5 -0
  84. data/pantograph/lib/pantograph/cli_tools_distributor.rb +183 -0
  85. data/pantograph/lib/pantograph/command_line_handler.rb +43 -0
  86. data/pantograph/lib/pantograph/commands_generator.rb +344 -0
  87. data/pantograph/lib/pantograph/configuration_helper.rb +26 -0
  88. data/pantograph/lib/pantograph/core_ext/bundler_monkey_patch.rb +14 -0
  89. data/pantograph/lib/pantograph/documentation/actions_list.rb +214 -0
  90. data/pantograph/lib/pantograph/documentation/docs_generator.rb +95 -0
  91. data/pantograph/lib/pantograph/documentation/markdown_docs_generator.rb +221 -0
  92. data/pantograph/lib/pantograph/environment_printer.rb +282 -0
  93. data/pantograph/lib/pantograph/erb_template_helper.rb +30 -0
  94. data/pantograph/lib/pantograph/features.rb +4 -0
  95. data/pantograph/lib/pantograph/helper/README.md +29 -0
  96. data/pantograph/lib/pantograph/helper/dotenv_helper.rb +50 -0
  97. data/pantograph/lib/pantograph/helper/gem_helper.rb +26 -0
  98. data/pantograph/lib/pantograph/helper/git_helper.rb +135 -0
  99. data/pantograph/lib/pantograph/helper/gradle_helper.rb +62 -0
  100. data/pantograph/lib/pantograph/helper/sh_helper.rb +134 -0
  101. data/pantograph/lib/pantograph/junit_generator.rb +27 -0
  102. data/pantograph/lib/pantograph/lane.rb +97 -0
  103. data/pantograph/lib/pantograph/lane_list.rb +77 -0
  104. data/pantograph/lib/pantograph/lane_manager.rb +140 -0
  105. data/pantograph/lib/pantograph/lane_manager_base.rb +92 -0
  106. data/pantograph/lib/pantograph/markdown_table_formatter.rb +62 -0
  107. data/pantograph/lib/pantograph/new_action.rb +47 -0
  108. data/pantograph/lib/pantograph/one_off.rb +45 -0
  109. data/pantograph/lib/pantograph/other_action.rb +29 -0
  110. data/pantograph/lib/pantograph/pant_file.rb +377 -0
  111. data/pantograph/lib/pantograph/pantograph_require.rb +75 -0
  112. data/pantograph/lib/pantograph/plugins/plugin_fetcher.rb +55 -0
  113. data/pantograph/lib/pantograph/plugins/plugin_generator.rb +86 -0
  114. data/pantograph/lib/pantograph/plugins/plugin_generator_ui.rb +19 -0
  115. data/pantograph/lib/pantograph/plugins/plugin_info.rb +49 -0
  116. data/pantograph/lib/pantograph/plugins/plugin_info_collector.rb +159 -0
  117. data/pantograph/lib/pantograph/plugins/plugin_manager.rb +387 -0
  118. data/pantograph/lib/pantograph/plugins/plugin_search.rb +46 -0
  119. data/pantograph/lib/pantograph/plugins/plugin_update_manager.rb +70 -0
  120. data/pantograph/lib/pantograph/plugins/plugins.rb +12 -0
  121. data/pantograph/lib/pantograph/plugins/template/%gem_name%.gemspec.erb +35 -0
  122. data/pantograph/lib/pantograph/plugins/template/.circleci/config.yml +43 -0
  123. data/pantograph/lib/pantograph/plugins/template/.gitignore +12 -0
  124. data/pantograph/lib/pantograph/plugins/template/.rspec +5 -0
  125. data/pantograph/lib/pantograph/plugins/template/.rubocop.yml +179 -0
  126. data/pantograph/lib/pantograph/plugins/template/.travis.yml +4 -0
  127. data/pantograph/lib/pantograph/plugins/template/Gemfile +6 -0
  128. data/pantograph/lib/pantograph/plugins/template/LICENSE.erb +21 -0
  129. data/pantograph/lib/pantograph/plugins/template/README.md.erb +52 -0
  130. data/pantograph/lib/pantograph/plugins/template/Rakefile +9 -0
  131. data/pantograph/lib/pantograph/plugins/template/lib/pantograph/plugin/%plugin_name%/actions/%plugin_name%_action.rb.erb +47 -0
  132. data/pantograph/lib/pantograph/plugins/template/lib/pantograph/plugin/%plugin_name%/helper/%plugin_name%_helper.rb.erb +16 -0
  133. data/pantograph/lib/pantograph/plugins/template/lib/pantograph/plugin/%plugin_name%/version.rb.erb +5 -0
  134. data/pantograph/lib/pantograph/plugins/template/lib/pantograph/plugin/%plugin_name%.rb.erb +16 -0
  135. data/pantograph/lib/pantograph/plugins/template/pantograph/Pantfile.erb +3 -0
  136. data/pantograph/lib/pantograph/plugins/template/pantograph/Pluginfile.erb +1 -0
  137. data/pantograph/lib/pantograph/plugins/template/spec/%plugin_name%_action_spec.rb.erb +9 -0
  138. data/pantograph/lib/pantograph/plugins/template/spec/spec_helper.rb.erb +15 -0
  139. data/pantograph/lib/pantograph/runner.rb +371 -0
  140. data/pantograph/lib/pantograph/server/action_command.rb +61 -0
  141. data/pantograph/lib/pantograph/server/action_command_return.rb +14 -0
  142. data/pantograph/lib/pantograph/server/command_executor.rb +7 -0
  143. data/pantograph/lib/pantograph/server/command_parser.rb +36 -0
  144. data/pantograph/lib/pantograph/server/control_command.rb +23 -0
  145. data/pantograph/lib/pantograph/server/json_return_value_processor.rb +72 -0
  146. data/pantograph/lib/pantograph/server/socket_server.rb +232 -0
  147. data/pantograph/lib/pantograph/server/socket_server_action_command_executor.rb +101 -0
  148. data/pantograph/lib/pantograph/setup/setup.rb +290 -0
  149. data/pantograph/lib/pantograph/setup/setup_android.rb +64 -0
  150. data/pantograph/lib/pantograph/setup/setup_ios.rb +412 -0
  151. data/pantograph/lib/pantograph/shells.rb +6 -0
  152. data/pantograph/lib/pantograph/supported_platforms.rb +28 -0
  153. data/pantograph/lib/pantograph/tools.rb +10 -0
  154. data/pantograph/lib/pantograph/version.rb +5 -0
  155. data/pantograph/lib/pantograph.rb +51 -0
  156. data/pantograph_core/README.md +79 -0
  157. data/pantograph_core/lib/assets/XMLTemplate.xml.erb +12 -0
  158. data/pantograph_core/lib/pantograph_core/analytics/action_completion_context.rb +34 -0
  159. data/pantograph_core/lib/pantograph_core/analytics/action_launch_context.rb +38 -0
  160. data/pantograph_core/lib/pantograph_core/analytics/analytics_event_builder.rb +23 -0
  161. data/pantograph_core/lib/pantograph_core/analytics/analytics_ingester_client.rb +54 -0
  162. data/pantograph_core/lib/pantograph_core/analytics/analytics_session.rb +71 -0
  163. data/pantograph_core/lib/pantograph_core/cert_checker.rb +116 -0
  164. data/pantograph_core/lib/pantograph_core/command_executor.rb +99 -0
  165. data/pantograph_core/lib/pantograph_core/configuration/commander_generator.rb +103 -0
  166. data/pantograph_core/lib/pantograph_core/configuration/config_item.rb +314 -0
  167. data/pantograph_core/lib/pantograph_core/configuration/configuration.rb +332 -0
  168. data/pantograph_core/lib/pantograph_core/configuration/configuration_file.rb +182 -0
  169. data/pantograph_core/lib/pantograph_core/core_ext/shellwords.rb +63 -0
  170. data/pantograph_core/lib/pantograph_core/core_ext/string.rb +17 -0
  171. data/pantograph_core/lib/pantograph_core/env.rb +9 -0
  172. data/pantograph_core/lib/pantograph_core/feature/feature.rb +51 -0
  173. data/pantograph_core/lib/pantograph_core/features.rb +4 -0
  174. data/pantograph_core/lib/pantograph_core/globals.rb +27 -0
  175. data/pantograph_core/lib/pantograph_core/helper.rb +409 -0
  176. data/pantograph_core/lib/pantograph_core/keychain_importer.rb +74 -0
  177. data/pantograph_core/lib/pantograph_core/languages.rb +14 -0
  178. data/pantograph_core/lib/pantograph_core/module.rb +29 -0
  179. data/pantograph_core/lib/pantograph_core/pantograph_folder.rb +39 -0
  180. data/pantograph_core/lib/pantograph_core/pantograph_pty.rb +57 -0
  181. data/pantograph_core/lib/pantograph_core/pkg_file_analyser.rb +44 -0
  182. data/pantograph_core/lib/pantograph_core/print_table.rb +131 -0
  183. data/pantograph_core/lib/pantograph_core/string_filters.rb +51 -0
  184. data/pantograph_core/lib/pantograph_core/swag.rb +85 -0
  185. data/pantograph_core/lib/pantograph_core/tag_version.rb +31 -0
  186. data/pantograph_core/lib/pantograph_core/test_parser.rb +107 -0
  187. data/pantograph_core/lib/pantograph_core/ui/disable_colors.rb +17 -0
  188. data/pantograph_core/lib/pantograph_core/ui/errors/pantograph_common_error.rb +19 -0
  189. data/pantograph_core/lib/pantograph_core/ui/errors/pantograph_crash.rb +11 -0
  190. data/pantograph_core/lib/pantograph_core/ui/errors/pantograph_error.rb +25 -0
  191. data/pantograph_core/lib/pantograph_core/ui/errors/pantograph_exception.rb +19 -0
  192. data/pantograph_core/lib/pantograph_core/ui/errors/pantograph_shell_error.rb +11 -0
  193. data/pantograph_core/lib/pantograph_core/ui/errors.rb +1 -0
  194. data/pantograph_core/lib/pantograph_core/ui/github_issue_inspector_reporter.rb +62 -0
  195. data/pantograph_core/lib/pantograph_core/ui/implementations/shell.rb +159 -0
  196. data/pantograph_core/lib/pantograph_core/ui/interface.rb +205 -0
  197. data/pantograph_core/lib/pantograph_core/ui/pantograph_runner.rb +276 -0
  198. data/pantograph_core/lib/pantograph_core/ui/ui.rb +26 -0
  199. data/pantograph_core/lib/pantograph_core/update_checker/changelog.rb +37 -0
  200. data/pantograph_core/lib/pantograph_core/update_checker/update_checker.rb +107 -0
  201. data/pantograph_core/lib/pantograph_core.rb +45 -0
  202. metadata +987 -0
@@ -0,0 +1,19 @@
1
+ module PantographCore
2
+ class Interface
3
+ class PantographException < StandardError
4
+ def prefix
5
+ '[PANTOGRAPH_EXCEPTION]'
6
+ end
7
+
8
+ def caused_by_calling_ui_method?(method_name: nil)
9
+ return false if backtrace.nil? || backtrace[0].nil? || method_name.nil?
10
+ first_frame = backtrace[0]
11
+ if first_frame.include?(method_name) && first_frame.include?('interface.rb')
12
+ true
13
+ else
14
+ false
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'pantograph_exception'
2
+
3
+ module PantographCore
4
+ class Interface
5
+ class PantographShellError < PantographException
6
+ def prefix
7
+ '[SHELL_ERROR]'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ Dir[File.dirname(__FILE__) + "/errors/*.rb"].each { |f| require_relative f }
@@ -0,0 +1,62 @@
1
+ require_relative '../helper'
2
+ require_relative '../globals'
3
+
4
+ module Pantograph
5
+ # Adds all the necessary emojis (obv)
6
+ #
7
+ class InspectorReporter
8
+ NUMBER_OF_ISSUES_INLINE = 3
9
+
10
+ # Called just as the investigation has begun.
11
+ def inspector_started_query(query, inspector)
12
+ puts("")
13
+ puts("Looking for related GitHub issues on #{inspector.repo_owner}/#{inspector.repo_name}...")
14
+ puts("Search query: #{query}") if PantographCore::Globals.verbose?
15
+ puts("")
16
+ end
17
+
18
+ # Called once the inspector has received a report with more than one issue.
19
+ def inspector_successfully_received_report(report, inspector)
20
+ report.issues[0..(NUMBER_OF_ISSUES_INLINE - 1)].each { |issue| print_issue_full(issue) }
21
+
22
+ if report.issues.count > NUMBER_OF_ISSUES_INLINE
23
+ report.url.sub!('\'', '%27')
24
+ puts("and #{report.total_results - NUMBER_OF_ISSUES_INLINE} more at: #{report.url}")
25
+ puts("")
26
+ end
27
+
28
+ print_open_link_hint
29
+ end
30
+
31
+ # Called once the report has been received, but when there are no issues found.
32
+ def inspector_received_empty_report(report, inspector)
33
+ puts("Found no similar issues. To create a new issue, please visit:")
34
+ puts("https://github.com/#{inspector.repo_owner}/#{inspector.repo_name}/issues/new")
35
+ puts("Run `pantograph env` to append the pantograph environment to your issue")
36
+ end
37
+
38
+ # Called when there have been networking issues in creating the report.
39
+ def inspector_could_not_create_report(error, query, inspector)
40
+ puts("Could not access the GitHub API, you may have better luck via the website.")
41
+ puts("https://github.com/#{inspector.repo_owner}/#{inspector.repo_name}/search?q=#{query}&type=Issues&utf8=✓")
42
+ puts("Error: #{error.name}")
43
+ end
44
+
45
+ private
46
+
47
+ def print_issue_full(issue)
48
+ resolved = issue.state == 'closed'
49
+ status = (resolved ? issue.state.green : issue.state.red)
50
+
51
+ puts("➡️ #{issue.title.yellow}")
52
+ puts(" #{issue.html_url} [#{status}] #{issue.comments} 💬")
53
+ puts(" #{Time.parse(issue.updated_at).to_pretty}")
54
+ puts("")
55
+ end
56
+
57
+ def print_open_link_hint(newline = false)
58
+ puts("") if newline
59
+ puts("🔗 You can ⌘ + double-click on links to open them directly in your browser.") if PantographCore::Helper.mac?
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,159 @@
1
+ require_relative '../../helper'
2
+ require_relative '../../globals'
3
+ require_relative '../../env'
4
+
5
+ require_relative '../interface'
6
+
7
+ module PantographCore
8
+ # Shell is the terminal output of things
9
+ # For documentation for each of the methods open `interface.rb`
10
+ class Shell < Interface
11
+ require 'tty-screen'
12
+
13
+ def log
14
+ return @log if @log
15
+
16
+ $stdout.sync = true
17
+
18
+ if Helper.test? && !ENV.key?('DEBUG')
19
+ $stdout.puts("Logging disabled while running tests. Force them by setting the DEBUG environment variable")
20
+ @log ||= Logger.new(nil) # don't show any logs when running tests
21
+ else
22
+ @log ||= Logger.new($stdout)
23
+ end
24
+
25
+ @log.formatter = proc do |severity, datetime, progname, msg|
26
+ "#{format_string(datetime, severity)}#{msg}\n"
27
+ end
28
+
29
+ @log
30
+ end
31
+
32
+ def format_string(datetime = Time.now, severity = "")
33
+ timezone_string = !PantographCore::Env.truthy?('PANTOGRAPH_SHOW_TIMEZONE') ? '' : ' %z'
34
+ if PantographCore::Globals.verbose?
35
+ return "#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%2N' + timezone_string)}]: "
36
+ elsif PantographCore::Env.truthy?("PANTOGRAPH_HIDE_TIMESTAMP")
37
+ return ""
38
+ else
39
+ return "[#{datetime.strftime('%H:%M:%S' + timezone_string)}]: "
40
+ end
41
+ end
42
+
43
+ #####################################################
44
+ # @!group Messaging: show text to the user
45
+ #####################################################
46
+
47
+ def error(message)
48
+ log.error(message.to_s.red)
49
+ end
50
+
51
+ def important(message)
52
+ log.warn(message.to_s.yellow)
53
+ end
54
+
55
+ def success(message)
56
+ log.info(message.to_s.green)
57
+ end
58
+
59
+ def message(message)
60
+ log.info(message.to_s)
61
+ end
62
+
63
+ def deprecated(message)
64
+ log.error(message.to_s.deprecated)
65
+ end
66
+
67
+ def command(message)
68
+ log.info("$ #{message}".cyan)
69
+ end
70
+
71
+ def command_output(message)
72
+ actual = (message.split("\r").last || "") # as clearing the line will remove the `>` and the time stamp
73
+ actual.split("\n").each do |msg|
74
+ if PantographCore::Env.truthy?("PANTOGRAPH_DISABLE_OUTPUT_FORMAT")
75
+ log.info(msg)
76
+ else
77
+ prefix = msg.include?("▸") ? "" : "▸ "
78
+ log.info(prefix + "" + msg.magenta)
79
+ end
80
+ end
81
+ end
82
+
83
+ def verbose(message)
84
+ log.debug(message.to_s) if PantographCore::Globals.verbose?
85
+ end
86
+
87
+ def header(message)
88
+ format = format_string
89
+ if message.length + 8 < TTY::Screen.width - format.length
90
+ message = "--- #{message} ---"
91
+ i = message.length
92
+ else
93
+ i = TTY::Screen.width - format.length
94
+ end
95
+ success("-" * i)
96
+ success(message)
97
+ success("-" * i)
98
+ end
99
+
100
+ def content_error(content, error_line)
101
+ error_line = error_line.to_i
102
+ return unless error_line > 0
103
+
104
+ contents = content.split(/\r?\n/).map(&:chomp)
105
+
106
+ start_line = error_line - 2 < 1 ? 1 : error_line - 2
107
+ end_line = error_line + 2 < contents.length ? error_line + 2 : contents.length
108
+
109
+ Range.new(start_line, end_line).each do |line|
110
+ str = line == error_line ? " => " : " "
111
+ str << line.to_s.rjust(Math.log10(end_line) + 1)
112
+ str << ":\t#{contents[line - 1]}"
113
+ error(str)
114
+ end
115
+ end
116
+
117
+ #####################################################
118
+ # @!group Errors: Inputs
119
+ #####################################################
120
+
121
+ def interactive?
122
+ interactive = true
123
+ interactive = false if $stdout.isatty == false
124
+ interactive = false if Helper.ci?
125
+ return interactive
126
+ end
127
+
128
+ def input(message)
129
+ verify_interactive!(message)
130
+ ask("#{format_string}#{message.to_s.yellow}").to_s.strip
131
+ end
132
+
133
+ def confirm(message)
134
+ verify_interactive!(message)
135
+ agree("#{format_string}#{message.to_s.yellow} (y/n)", true)
136
+ end
137
+
138
+ def select(message, options)
139
+ verify_interactive!(message)
140
+
141
+ important(message)
142
+ choose(*options)
143
+ end
144
+
145
+ def password(message)
146
+ verify_interactive!(message)
147
+
148
+ ask("#{format_string}#{message.to_s.yellow}") { |q| q.echo = "*" }
149
+ end
150
+
151
+ private
152
+
153
+ def verify_interactive!(message)
154
+ return if interactive?
155
+ important(message)
156
+ crash!("Could not retrieve response as pantograph runs in non-interactive mode")
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,205 @@
1
+ require_relative 'errors'
2
+
3
+ module PantographCore
4
+ # Abstract super class
5
+ class Interface
6
+ #####################################################
7
+ # @!group Messaging: show text to the user
8
+ #####################################################
9
+
10
+ # Level Error: Can be used to show additional error
11
+ # information before actually raising an exception
12
+ # or can be used to just show an error from which
13
+ # pantograph can recover (much magic)
14
+ #
15
+ # By default those messages are shown in red
16
+ def error(_message)
17
+ not_implemented(__method__)
18
+ end
19
+
20
+ # Level Important: Can be used to show warnings to the user
21
+ # not necessarily negative, but something the user should
22
+ # be aware of.
23
+ #
24
+ # By default those messages are shown in yellow
25
+ def important(_message)
26
+ not_implemented(__method__)
27
+ end
28
+
29
+ # Level Success: Show that something was successful
30
+ #
31
+ # By default those messages are shown in green
32
+ def success(_message)
33
+ not_implemented(__method__)
34
+ end
35
+
36
+ # Level Message: Show a neutral message to the user
37
+ #
38
+ # By default those messages shown in white/black
39
+ def message(_message)
40
+ not_implemented(__method__)
41
+ end
42
+
43
+ # Level Deprecated: Show that a particular function is deprecated
44
+ #
45
+ # By default those messages shown in strong blue
46
+ def deprecated(_message)
47
+ not_implemented(__method__)
48
+ end
49
+
50
+ # Level Command: Print out a terminal command that is being
51
+ # executed.
52
+ #
53
+ # By default those messages shown in cyan
54
+ def command(_message)
55
+ not_implemented(__method__)
56
+ end
57
+
58
+ # Level Command Output: Print the output of a command with
59
+ # this method
60
+ #
61
+ # By default those messages shown in magenta
62
+ def command_output(_message)
63
+ not_implemented(__method__)
64
+ end
65
+
66
+ # Level Verbose: Print out additional information for the
67
+ # users that are interested. Will only be printed when
68
+ # PantographCore::Globals.verbose? = true
69
+ #
70
+ # By default those messages are shown in white
71
+ def verbose(_message)
72
+ not_implemented(__method__)
73
+ end
74
+
75
+ # Print a header = a text in a box
76
+ # use this if this message is really important
77
+ def header(_message)
78
+ not_implemented(__method__)
79
+ end
80
+
81
+ # Print lines of content around specific line where
82
+ # failed to parse.
83
+ #
84
+ # This message will be shown as error
85
+ def content_error(content, error_line)
86
+ not_implemented(__method__)
87
+ end
88
+
89
+ #####################################################
90
+ # @!group Errors: Inputs
91
+ #####################################################
92
+
93
+ # Is is possible to ask the user questions?
94
+ def interactive?
95
+ not_implemented(__method__)
96
+ end
97
+
98
+ # get a standard text input (single line)
99
+ def input(_message)
100
+ not_implemented(__method__)
101
+ end
102
+
103
+ # A simple yes or no question
104
+ def confirm(_message)
105
+ not_implemented(__method__)
106
+ end
107
+
108
+ # Let the user select one out of x items
109
+ # return value is the value of the option the user chose
110
+ def select(_message, _options)
111
+ not_implemented(__method__)
112
+ end
113
+
114
+ # Password input for the user, text field shouldn't show
115
+ # plain text
116
+ def password(_message)
117
+ not_implemented(__method__)
118
+ end
119
+
120
+ #####################################################
121
+ # @!group Abort helper methods
122
+ #####################################################
123
+
124
+ # Pass an exception to this method to exit the program
125
+ # using the given exception
126
+ # Use this method instead of user_error! if this error is
127
+ # unexpected, e.g. an invalid server response that shouldn't happen
128
+ def crash!(exception)
129
+ raise PantographCrash.new, exception.to_s
130
+ end
131
+
132
+ # Use this method to exit the program because of an user error
133
+ # e.g. app doesn't exist on the given Developer Account
134
+ # or invalid user credentials
135
+ # or scan tests fail
136
+ # This will show the error message, but doesn't show the full
137
+ # stack trace
138
+ # Basically this should be used when you actively catch the error
139
+ # and want to show a nice error message to the user
140
+ def user_error!(error_message, options = {})
141
+ raise PantographError.new(options), error_message.to_s
142
+ end
143
+
144
+ # Use this method to exit the program because of a shell command
145
+ # failure -- the command returned a non-zero response. This does
146
+ # not specify the nature of the error. The error might be from a
147
+ # programming error, a user error, or an expected error because
148
+ # the user of the Pantfile doesn't have their environment set up
149
+ # properly. Because of this, when these errors occur, it means
150
+ # that the caller of the shell command did not adequate error
151
+ # handling and the caller error handling should be improved.
152
+ def shell_error!(error_message, options = {})
153
+ raise PantographShellError.new(options), error_message.to_s
154
+ end
155
+
156
+ # Use this method to exit the program because of a build failure
157
+ # that's caused by the source code of the user. Example for this
158
+ # is that gym will fail when the code doesn't compile or because
159
+ # settings for the project are incorrect.
160
+ # By using this method we'll have more accurate results about
161
+ # pantograph failures
162
+ def build_failure!(error_message, options = {})
163
+ raise PantographBuildFailure.new(options), error_message.to_s
164
+ end
165
+
166
+ # Use this method to exit the program because of a test failure
167
+ # that's caused by the source code of the user. Example for this
168
+ # is that scan will fail when the tests fail.
169
+ # By using this method we'll have more accurate results about
170
+ # pantograph failures
171
+ def test_failure!(error_message)
172
+ raise PantographTestFailure.new, error_message
173
+ end
174
+
175
+ # Use this method to exit the program because of terminal state
176
+ # that is neither the fault of pantograph, nor a problem with the
177
+ # user's input. Using this method instead of user_error! will
178
+ # avoid tracking this outcome as a pantograph failure.
179
+ #
180
+ # e.g. tests ran successfully, but no screenshots were found
181
+ #
182
+ # This will show the message, but hide the full stack trace.
183
+ def abort_with_message!(message)
184
+ raise PantographCommonException.new, message
185
+ end
186
+
187
+ #####################################################
188
+ # @!group Helpers
189
+ #####################################################
190
+ def not_implemented(method_name)
191
+ require_relative 'ui'
192
+ UI.user_error!("Current UI '#{self}' doesn't support method '#{method_name}'")
193
+ end
194
+
195
+ def to_s
196
+ self.class.name.split('::').last
197
+ end
198
+ end
199
+ end
200
+
201
+ class String
202
+ def deprecated
203
+ self.bold.blue
204
+ end
205
+ end