pantograph 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +1 -0
- data/LICENSE +21 -0
- data/README.md +197 -0
- data/bin/bin-proxy +19 -0
- data/bin/pantograph +23 -0
- data/pantograph/README.md +11 -0
- data/pantograph/lib/assets/ActionDetails.md.erb +106 -0
- data/pantograph/lib/assets/Actions.md.erb +43 -0
- data/pantograph/lib/assets/DefaultPantfileTemplate +20 -0
- data/pantograph/lib/assets/completions/completion.bash +23 -0
- data/pantograph/lib/assets/completions/completion.fish +39 -0
- data/pantograph/lib/assets/completions/completion.sh +12 -0
- data/pantograph/lib/assets/completions/completion.zsh +23 -0
- data/pantograph/lib/assets/custom_action_template.rb +80 -0
- data/pantograph/lib/assets/report_template.xml.erb +15 -0
- data/pantograph/lib/pantograph/action.rb +194 -0
- data/pantograph/lib/pantograph/action_collector.rb +35 -0
- data/pantograph/lib/pantograph/actions/README.md +3 -0
- data/pantograph/lib/pantograph/actions/actions_helper.rb +166 -0
- data/pantograph/lib/pantograph/actions/add_extra_platforms.rb +45 -0
- data/pantograph/lib/pantograph/actions/artifactory.rb +157 -0
- data/pantograph/lib/pantograph/actions/bundle_install.rb +156 -0
- data/pantograph/lib/pantograph/actions/changelog_from_git_commits.rb +197 -0
- data/pantograph/lib/pantograph/actions/clipboard.rb +52 -0
- data/pantograph/lib/pantograph/actions/cloc.rb +89 -0
- data/pantograph/lib/pantograph/actions/create_pull_request.rb +190 -0
- data/pantograph/lib/pantograph/actions/danger.rb +131 -0
- data/pantograph/lib/pantograph/actions/debug.rb +32 -0
- data/pantograph/lib/pantograph/actions/default_platform.rb +47 -0
- data/pantograph/lib/pantograph/actions/download.rb +76 -0
- data/pantograph/lib/pantograph/actions/echo.rb +14 -0
- data/pantograph/lib/pantograph/actions/ensure_bundle_exec.rb +59 -0
- data/pantograph/lib/pantograph/actions/ensure_env_vars.rb +58 -0
- data/pantograph/lib/pantograph/actions/ensure_git_branch.rb +69 -0
- data/pantograph/lib/pantograph/actions/ensure_git_status_clean.rb +81 -0
- data/pantograph/lib/pantograph/actions/erb.rb +88 -0
- data/pantograph/lib/pantograph/actions/get_build_number_repository.rb +120 -0
- data/pantograph/lib/pantograph/actions/get_github_release.rb +163 -0
- data/pantograph/lib/pantograph/actions/git_add.rb +93 -0
- data/pantograph/lib/pantograph/actions/git_branch.rb +58 -0
- data/pantograph/lib/pantograph/actions/git_commit.rb +80 -0
- data/pantograph/lib/pantograph/actions/git_pull.rb +53 -0
- data/pantograph/lib/pantograph/actions/git_submodule_update.rb +52 -0
- data/pantograph/lib/pantograph/actions/git_tag_exists.rb +74 -0
- data/pantograph/lib/pantograph/actions/github_api.rb +262 -0
- data/pantograph/lib/pantograph/actions/gradle.rb +278 -0
- data/pantograph/lib/pantograph/actions/import.rb +49 -0
- data/pantograph/lib/pantograph/actions/import_from_git.rb +71 -0
- data/pantograph/lib/pantograph/actions/is_ci.rb +51 -0
- data/pantograph/lib/pantograph/actions/jira.rb +115 -0
- data/pantograph/lib/pantograph/actions/lane_context.rb +60 -0
- data/pantograph/lib/pantograph/actions/last_git_commit.rb +58 -0
- data/pantograph/lib/pantograph/actions/last_git_tag.rb +51 -0
- data/pantograph/lib/pantograph/actions/make_changelog_from_jenkins.rb +81 -0
- data/pantograph/lib/pantograph/actions/min_pantograph_version.rb +57 -0
- data/pantograph/lib/pantograph/actions/nexus_upload.rb +230 -0
- data/pantograph/lib/pantograph/actions/notification.rb +75 -0
- data/pantograph/lib/pantograph/actions/number_of_commits.rb +75 -0
- data/pantograph/lib/pantograph/actions/opt_out_usage.rb +40 -0
- data/pantograph/lib/pantograph/actions/pantograph_version.rb +15 -0
- data/pantograph/lib/pantograph/actions/println.rb +14 -0
- data/pantograph/lib/pantograph/actions/prompt.rb +119 -0
- data/pantograph/lib/pantograph/actions/push_git_tags.rb +76 -0
- data/pantograph/lib/pantograph/actions/push_to_git_remote.rb +127 -0
- data/pantograph/lib/pantograph/actions/puts.rb +68 -0
- data/pantograph/lib/pantograph/actions/reset_git_repo.rb +121 -0
- data/pantograph/lib/pantograph/actions/rocket.rb +83 -0
- data/pantograph/lib/pantograph/actions/rsync.rb +74 -0
- data/pantograph/lib/pantograph/actions/ruby_version.rb +56 -0
- data/pantograph/lib/pantograph/actions/say.rb +56 -0
- data/pantograph/lib/pantograph/actions/scp.rb +114 -0
- data/pantograph/lib/pantograph/actions/set_github_release.rb +274 -0
- data/pantograph/lib/pantograph/actions/sh.rb +71 -0
- data/pantograph/lib/pantograph/actions/skip_docs.rb +52 -0
- data/pantograph/lib/pantograph/actions/slack.rb +288 -0
- data/pantograph/lib/pantograph/actions/sonar.rb +156 -0
- data/pantograph/lib/pantograph/actions/ssh.rb +162 -0
- data/pantograph/lib/pantograph/actions/twitter.rb +89 -0
- data/pantograph/lib/pantograph/actions/update_pantograph.rb +177 -0
- data/pantograph/lib/pantograph/actions/zip.rb +120 -0
- data/pantograph/lib/pantograph/auto_complete.rb +82 -0
- data/pantograph/lib/pantograph/boolean.rb +5 -0
- data/pantograph/lib/pantograph/cli_tools_distributor.rb +183 -0
- data/pantograph/lib/pantograph/command_line_handler.rb +43 -0
- data/pantograph/lib/pantograph/commands_generator.rb +344 -0
- data/pantograph/lib/pantograph/configuration_helper.rb +26 -0
- data/pantograph/lib/pantograph/core_ext/bundler_monkey_patch.rb +14 -0
- data/pantograph/lib/pantograph/documentation/actions_list.rb +214 -0
- data/pantograph/lib/pantograph/documentation/docs_generator.rb +95 -0
- data/pantograph/lib/pantograph/documentation/markdown_docs_generator.rb +221 -0
- data/pantograph/lib/pantograph/environment_printer.rb +282 -0
- data/pantograph/lib/pantograph/erb_template_helper.rb +30 -0
- data/pantograph/lib/pantograph/features.rb +4 -0
- data/pantograph/lib/pantograph/helper/README.md +29 -0
- data/pantograph/lib/pantograph/helper/dotenv_helper.rb +50 -0
- data/pantograph/lib/pantograph/helper/gem_helper.rb +26 -0
- data/pantograph/lib/pantograph/helper/git_helper.rb +135 -0
- data/pantograph/lib/pantograph/helper/gradle_helper.rb +62 -0
- data/pantograph/lib/pantograph/helper/sh_helper.rb +134 -0
- data/pantograph/lib/pantograph/junit_generator.rb +27 -0
- data/pantograph/lib/pantograph/lane.rb +97 -0
- data/pantograph/lib/pantograph/lane_list.rb +77 -0
- data/pantograph/lib/pantograph/lane_manager.rb +140 -0
- data/pantograph/lib/pantograph/lane_manager_base.rb +92 -0
- data/pantograph/lib/pantograph/markdown_table_formatter.rb +62 -0
- data/pantograph/lib/pantograph/new_action.rb +47 -0
- data/pantograph/lib/pantograph/one_off.rb +45 -0
- data/pantograph/lib/pantograph/other_action.rb +29 -0
- data/pantograph/lib/pantograph/pant_file.rb +377 -0
- data/pantograph/lib/pantograph/pantograph_require.rb +75 -0
- data/pantograph/lib/pantograph/plugins/plugin_fetcher.rb +55 -0
- data/pantograph/lib/pantograph/plugins/plugin_generator.rb +86 -0
- data/pantograph/lib/pantograph/plugins/plugin_generator_ui.rb +19 -0
- data/pantograph/lib/pantograph/plugins/plugin_info.rb +49 -0
- data/pantograph/lib/pantograph/plugins/plugin_info_collector.rb +159 -0
- data/pantograph/lib/pantograph/plugins/plugin_manager.rb +387 -0
- data/pantograph/lib/pantograph/plugins/plugin_search.rb +46 -0
- data/pantograph/lib/pantograph/plugins/plugin_update_manager.rb +70 -0
- data/pantograph/lib/pantograph/plugins/plugins.rb +12 -0
- data/pantograph/lib/pantograph/plugins/template/%gem_name%.gemspec.erb +35 -0
- data/pantograph/lib/pantograph/plugins/template/.circleci/config.yml +43 -0
- data/pantograph/lib/pantograph/plugins/template/.gitignore +12 -0
- data/pantograph/lib/pantograph/plugins/template/.rspec +5 -0
- data/pantograph/lib/pantograph/plugins/template/.rubocop.yml +179 -0
- data/pantograph/lib/pantograph/plugins/template/.travis.yml +4 -0
- data/pantograph/lib/pantograph/plugins/template/Gemfile +6 -0
- data/pantograph/lib/pantograph/plugins/template/LICENSE.erb +21 -0
- data/pantograph/lib/pantograph/plugins/template/README.md.erb +52 -0
- data/pantograph/lib/pantograph/plugins/template/Rakefile +9 -0
- data/pantograph/lib/pantograph/plugins/template/lib/pantograph/plugin/%plugin_name%/actions/%plugin_name%_action.rb.erb +47 -0
- data/pantograph/lib/pantograph/plugins/template/lib/pantograph/plugin/%plugin_name%/helper/%plugin_name%_helper.rb.erb +16 -0
- data/pantograph/lib/pantograph/plugins/template/lib/pantograph/plugin/%plugin_name%/version.rb.erb +5 -0
- data/pantograph/lib/pantograph/plugins/template/lib/pantograph/plugin/%plugin_name%.rb.erb +16 -0
- data/pantograph/lib/pantograph/plugins/template/pantograph/Pantfile.erb +3 -0
- data/pantograph/lib/pantograph/plugins/template/pantograph/Pluginfile.erb +1 -0
- data/pantograph/lib/pantograph/plugins/template/spec/%plugin_name%_action_spec.rb.erb +9 -0
- data/pantograph/lib/pantograph/plugins/template/spec/spec_helper.rb.erb +15 -0
- data/pantograph/lib/pantograph/runner.rb +371 -0
- data/pantograph/lib/pantograph/server/action_command.rb +61 -0
- data/pantograph/lib/pantograph/server/action_command_return.rb +14 -0
- data/pantograph/lib/pantograph/server/command_executor.rb +7 -0
- data/pantograph/lib/pantograph/server/command_parser.rb +36 -0
- data/pantograph/lib/pantograph/server/control_command.rb +23 -0
- data/pantograph/lib/pantograph/server/json_return_value_processor.rb +72 -0
- data/pantograph/lib/pantograph/server/socket_server.rb +232 -0
- data/pantograph/lib/pantograph/server/socket_server_action_command_executor.rb +101 -0
- data/pantograph/lib/pantograph/setup/setup.rb +290 -0
- data/pantograph/lib/pantograph/setup/setup_android.rb +64 -0
- data/pantograph/lib/pantograph/setup/setup_ios.rb +412 -0
- data/pantograph/lib/pantograph/shells.rb +6 -0
- data/pantograph/lib/pantograph/supported_platforms.rb +28 -0
- data/pantograph/lib/pantograph/tools.rb +10 -0
- data/pantograph/lib/pantograph/version.rb +5 -0
- data/pantograph/lib/pantograph.rb +51 -0
- data/pantograph_core/README.md +79 -0
- data/pantograph_core/lib/assets/XMLTemplate.xml.erb +12 -0
- data/pantograph_core/lib/pantograph_core/analytics/action_completion_context.rb +34 -0
- data/pantograph_core/lib/pantograph_core/analytics/action_launch_context.rb +38 -0
- data/pantograph_core/lib/pantograph_core/analytics/analytics_event_builder.rb +23 -0
- data/pantograph_core/lib/pantograph_core/analytics/analytics_ingester_client.rb +54 -0
- data/pantograph_core/lib/pantograph_core/analytics/analytics_session.rb +71 -0
- data/pantograph_core/lib/pantograph_core/cert_checker.rb +116 -0
- data/pantograph_core/lib/pantograph_core/command_executor.rb +99 -0
- data/pantograph_core/lib/pantograph_core/configuration/commander_generator.rb +103 -0
- data/pantograph_core/lib/pantograph_core/configuration/config_item.rb +314 -0
- data/pantograph_core/lib/pantograph_core/configuration/configuration.rb +332 -0
- data/pantograph_core/lib/pantograph_core/configuration/configuration_file.rb +182 -0
- data/pantograph_core/lib/pantograph_core/core_ext/shellwords.rb +63 -0
- data/pantograph_core/lib/pantograph_core/core_ext/string.rb +17 -0
- data/pantograph_core/lib/pantograph_core/env.rb +9 -0
- data/pantograph_core/lib/pantograph_core/feature/feature.rb +51 -0
- data/pantograph_core/lib/pantograph_core/features.rb +4 -0
- data/pantograph_core/lib/pantograph_core/globals.rb +27 -0
- data/pantograph_core/lib/pantograph_core/helper.rb +409 -0
- data/pantograph_core/lib/pantograph_core/keychain_importer.rb +74 -0
- data/pantograph_core/lib/pantograph_core/languages.rb +14 -0
- data/pantograph_core/lib/pantograph_core/module.rb +29 -0
- data/pantograph_core/lib/pantograph_core/pantograph_folder.rb +39 -0
- data/pantograph_core/lib/pantograph_core/pantograph_pty.rb +57 -0
- data/pantograph_core/lib/pantograph_core/pkg_file_analyser.rb +44 -0
- data/pantograph_core/lib/pantograph_core/print_table.rb +131 -0
- data/pantograph_core/lib/pantograph_core/string_filters.rb +51 -0
- data/pantograph_core/lib/pantograph_core/swag.rb +85 -0
- data/pantograph_core/lib/pantograph_core/tag_version.rb +31 -0
- data/pantograph_core/lib/pantograph_core/test_parser.rb +107 -0
- data/pantograph_core/lib/pantograph_core/ui/disable_colors.rb +17 -0
- data/pantograph_core/lib/pantograph_core/ui/errors/pantograph_common_error.rb +19 -0
- data/pantograph_core/lib/pantograph_core/ui/errors/pantograph_crash.rb +11 -0
- data/pantograph_core/lib/pantograph_core/ui/errors/pantograph_error.rb +25 -0
- data/pantograph_core/lib/pantograph_core/ui/errors/pantograph_exception.rb +19 -0
- data/pantograph_core/lib/pantograph_core/ui/errors/pantograph_shell_error.rb +11 -0
- data/pantograph_core/lib/pantograph_core/ui/errors.rb +1 -0
- data/pantograph_core/lib/pantograph_core/ui/github_issue_inspector_reporter.rb +62 -0
- data/pantograph_core/lib/pantograph_core/ui/implementations/shell.rb +159 -0
- data/pantograph_core/lib/pantograph_core/ui/interface.rb +205 -0
- data/pantograph_core/lib/pantograph_core/ui/pantograph_runner.rb +276 -0
- data/pantograph_core/lib/pantograph_core/ui/ui.rb +26 -0
- data/pantograph_core/lib/pantograph_core/update_checker/changelog.rb +37 -0
- data/pantograph_core/lib/pantograph_core/update_checker/update_checker.rb +107 -0
- data/pantograph_core/lib/pantograph_core.rb +45 -0
- metadata +987 -0
@@ -0,0 +1,182 @@
|
|
1
|
+
require_relative '../print_table'
|
2
|
+
require_relative '../ui/ui'
|
3
|
+
|
4
|
+
module PantographCore
|
5
|
+
# Responsible for loading configuration files
|
6
|
+
class ConfigurationFile
|
7
|
+
class ExceptionWhileParsingError < RuntimeError
|
8
|
+
attr_reader :wrapped_exception
|
9
|
+
attr_reader :recovered_options
|
10
|
+
|
11
|
+
def initialize(wrapped_ex, options)
|
12
|
+
@wrapped_exception = wrapped_ex
|
13
|
+
@recovered_options = options
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Available keys from the config file
|
18
|
+
attr_accessor :available_keys
|
19
|
+
|
20
|
+
# After loading, contains all the found options
|
21
|
+
attr_accessor :options
|
22
|
+
|
23
|
+
# Path to the config file represented by the current object
|
24
|
+
attr_accessor :configfile_path
|
25
|
+
|
26
|
+
# @param config [PantographCore::Configuration] is used to gather required information about the configuration
|
27
|
+
# @param path [String] The path to the configuration file to use
|
28
|
+
def initialize(config, path, block_for_missing, skip_printing_values = false)
|
29
|
+
self.available_keys = config.all_keys
|
30
|
+
self.configfile_path = path
|
31
|
+
self.options = {}
|
32
|
+
|
33
|
+
@block_for_missing = block_for_missing
|
34
|
+
content = File.read(path, encoding: "utf-8")
|
35
|
+
|
36
|
+
# From https://github.com/orta/danger/blob/master/lib/danger/Dangerfile.rb
|
37
|
+
if content.tr!('“”‘’‛', %(""'''))
|
38
|
+
UI.error("Your #{File.basename(path)} has had smart quotes sanitised. " \
|
39
|
+
'To avoid issues in the future, you should not use ' \
|
40
|
+
'TextEdit for editing it. If you are not using TextEdit, ' \
|
41
|
+
'you should turn off smart quotes in your editor of choice.')
|
42
|
+
end
|
43
|
+
|
44
|
+
begin
|
45
|
+
# rubocop:disable Security/Eval
|
46
|
+
eval(content) # this is okay in this case
|
47
|
+
# rubocop:enable Security/Eval
|
48
|
+
|
49
|
+
print_resulting_config_values unless skip_printing_values # only on success
|
50
|
+
rescue SyntaxError => ex
|
51
|
+
line = ex.to_s.match(/\(eval\):(\d+)/)[1]
|
52
|
+
UI.error("Error in your #{File.basename(path)} at line #{line}")
|
53
|
+
UI.content_error(content, line)
|
54
|
+
UI.user_error!("Syntax error in your configuration file '#{path}' on line #{line}: #{ex}")
|
55
|
+
rescue => ex
|
56
|
+
raise ExceptionWhileParsingError.new(ex, self.options), "Error while parsing config file at #{path}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def print_resulting_config_values
|
61
|
+
require 'terminal-table'
|
62
|
+
UI.success("Successfully loaded '#{File.expand_path(self.configfile_path)}' 📄")
|
63
|
+
|
64
|
+
# Show message when self.modified_values is empty
|
65
|
+
if self.modified_values.empty?
|
66
|
+
UI.important("No values defined in '#{self.configfile_path}'")
|
67
|
+
return
|
68
|
+
end
|
69
|
+
|
70
|
+
rows = self.modified_values.collect do |key, value|
|
71
|
+
[key, value] if value.to_s.length > 0
|
72
|
+
end.compact
|
73
|
+
|
74
|
+
puts("")
|
75
|
+
puts(Terminal::Table.new(rows: PantographCore::PrintTable.transform_output(rows),
|
76
|
+
title: "Detected Values from '#{self.configfile_path}'"))
|
77
|
+
puts("")
|
78
|
+
end
|
79
|
+
|
80
|
+
# This is used to display only the values that have changed in the summary table
|
81
|
+
def modified_values
|
82
|
+
@modified_values ||= {}
|
83
|
+
end
|
84
|
+
|
85
|
+
def method_missing(method_sym, *arguments, &block)
|
86
|
+
# First, check if the key is actually available
|
87
|
+
return if self.options.key?(method_sym)
|
88
|
+
|
89
|
+
if self.available_keys.include?(method_sym)
|
90
|
+
|
91
|
+
value = arguments.first
|
92
|
+
value = yield if value.nil? && block_given?
|
93
|
+
|
94
|
+
if value.nil?
|
95
|
+
unless block_given?
|
96
|
+
# The config file has something like this:
|
97
|
+
#
|
98
|
+
# clean
|
99
|
+
#
|
100
|
+
# without specifying a value for the method call
|
101
|
+
# or a block. This is most likely a user error
|
102
|
+
# So we tell the user that they can provide a value
|
103
|
+
warning = ["In the config file '#{self.configfile_path}'"]
|
104
|
+
warning << "you have the line #{method_sym}, but didn't provide"
|
105
|
+
warning << "any value. Make sure to append a value right after the"
|
106
|
+
warning << "option name. Make sure to check the docs for more information"
|
107
|
+
UI.important(warning.join(" "))
|
108
|
+
end
|
109
|
+
return
|
110
|
+
end
|
111
|
+
|
112
|
+
self.modified_values[method_sym] = value
|
113
|
+
|
114
|
+
# to support frozen strings (e.g. ENV variables) too
|
115
|
+
# we have to dupe the value
|
116
|
+
# in < Ruby 2.4.0 `.dup` is not support by boolean values
|
117
|
+
# and there is no good way to check if a class actually
|
118
|
+
# responds to `dup`, so we have to rescue the exception
|
119
|
+
begin
|
120
|
+
value = value.dup
|
121
|
+
rescue TypeError
|
122
|
+
# Nothing specific to do here, if we can't dupe, we just
|
123
|
+
# deal with it (boolean values can't be from env variables anyway)
|
124
|
+
end
|
125
|
+
self.options[method_sym] = value
|
126
|
+
else
|
127
|
+
# We can't set this value, maybe the tool using this configuration system has its own
|
128
|
+
# way of handling this block, as this might be a special block (e.g. ipa block) that's only
|
129
|
+
# executed on demand
|
130
|
+
if @block_for_missing
|
131
|
+
@block_for_missing.call(method_sym, arguments, block)
|
132
|
+
else
|
133
|
+
self.options[method_sym] = '' # important, since this will raise a good exception for free
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Override configuration for a specific lane. If received lane name does not
|
139
|
+
# match the lane name available as environment variable, no changes will
|
140
|
+
# be applied.
|
141
|
+
#
|
142
|
+
# @param lane_name Symbol representing a lane name.
|
143
|
+
# @yield Block to run for overriding configuration values.
|
144
|
+
#
|
145
|
+
def for_lane(lane_name)
|
146
|
+
if ENV["PANTOGRAPH_LANE_NAME"] == lane_name.to_s
|
147
|
+
with_a_clean_config_merged_when_complete do
|
148
|
+
yield
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# Override configuration for a specific platform. If received platform name
|
154
|
+
# does not match the platform name available as environment variable, no
|
155
|
+
# changes will be applied.
|
156
|
+
#
|
157
|
+
# @param platform_name Symbol representing a platform name.
|
158
|
+
# @yield Block to run for overriding configuration values.
|
159
|
+
#
|
160
|
+
def for_platform(platform_name)
|
161
|
+
if ENV["PANTOGRAPH_PLATFORM_NAME"] == platform_name.to_s
|
162
|
+
with_a_clean_config_merged_when_complete do
|
163
|
+
yield
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# Allows a configuration block (for_lane, for_platform) to get a clean
|
169
|
+
# configuration for applying values, so that values can be overridden
|
170
|
+
# (once) again. Those values are then merged into the surrounding
|
171
|
+
# configuration as the block completes
|
172
|
+
def with_a_clean_config_merged_when_complete
|
173
|
+
previous_config = self.options.dup
|
174
|
+
self.options = {}
|
175
|
+
begin
|
176
|
+
yield
|
177
|
+
ensure
|
178
|
+
self.options = previous_config.merge(self.options)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'shellwords'
|
3
|
+
|
4
|
+
# Here be monkey patches
|
5
|
+
|
6
|
+
class String
|
7
|
+
# CrossplatformShellwords
|
8
|
+
def shellescape
|
9
|
+
CrossplatformShellwords.shellescape(self)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Array
|
14
|
+
def shelljoin
|
15
|
+
CrossplatformShellwords.shelljoin(self)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Here be helper
|
20
|
+
|
21
|
+
module CrossplatformShellwords
|
22
|
+
# handle switching between implementations of shellescape
|
23
|
+
def shellescape(str)
|
24
|
+
if PantographCore::Helper.windows?
|
25
|
+
WindowsShellwords.shellescape(str)
|
26
|
+
else
|
27
|
+
# using `escape` instead of expected `shellescape` here
|
28
|
+
# which corresponds to Shellword's `String.shellescape` implementation
|
29
|
+
# https://github.com/ruby/ruby/blob/1cf2bb4b2085758112503e7da7414d1ef52d4f48/lib/shellwords.rb#L216
|
30
|
+
Shellwords.escape(str)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
module_function :shellescape
|
34
|
+
|
35
|
+
# make sure local implementation is also used in shelljoin
|
36
|
+
def shelljoin(array)
|
37
|
+
array.map { |arg| shellescape(arg) }.join(' ')
|
38
|
+
end
|
39
|
+
module_function :shelljoin
|
40
|
+
end
|
41
|
+
|
42
|
+
# Windows implementation
|
43
|
+
module WindowsShellwords
|
44
|
+
def shellescape(str)
|
45
|
+
str = str.to_s
|
46
|
+
|
47
|
+
# An empty argument will be skipped, so return empty quotes.
|
48
|
+
# https://github.com/ruby/ruby/blob/a6413848153e6c37f6b0fea64e3e871460732e34/lib/shellwords.rb#L142-L143
|
49
|
+
return '""'.dup if str.empty?
|
50
|
+
|
51
|
+
str = str.dup
|
52
|
+
|
53
|
+
# wrap in double quotes if contains space
|
54
|
+
if str =~ /\s/
|
55
|
+
# double quotes have to be doubled if will be quoted
|
56
|
+
str.gsub!('"', '""')
|
57
|
+
return '"' + str + '"'
|
58
|
+
else
|
59
|
+
return str
|
60
|
+
end
|
61
|
+
end
|
62
|
+
module_function :shellescape
|
63
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class String
|
2
|
+
def pantograph_class
|
3
|
+
split('_').collect!(&:capitalize).join
|
4
|
+
end
|
5
|
+
|
6
|
+
# def pantograph_module
|
7
|
+
# self == "pem" ? 'PEM' : self.pantograph_class
|
8
|
+
# end
|
9
|
+
|
10
|
+
def pantograph_underscore
|
11
|
+
self.gsub(/::/, '/').
|
12
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
13
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
14
|
+
tr("-", "_").
|
15
|
+
downcase
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative '../env'
|
2
|
+
|
3
|
+
module PantographCore
|
4
|
+
class Feature
|
5
|
+
class << self
|
6
|
+
attr_reader :features
|
7
|
+
|
8
|
+
def register(env_var: nil, description: nil)
|
9
|
+
feature = self.new(description: description, env_var: env_var)
|
10
|
+
@features[feature.env_var] = feature
|
11
|
+
end
|
12
|
+
|
13
|
+
def enabled?(env_var)
|
14
|
+
feature = @features[env_var]
|
15
|
+
return false if feature.nil?
|
16
|
+
return PantographCore::Env.truthy?(feature.env_var)
|
17
|
+
end
|
18
|
+
|
19
|
+
def register_class_method(klass: nil, symbol: nil, disabled_symbol: nil, enabled_symbol: nil, env_var: nil)
|
20
|
+
return if klass.nil? || symbol.nil? || disabled_symbol.nil? || enabled_symbol.nil? || env_var.nil?
|
21
|
+
klass.define_singleton_method(symbol) do |*args|
|
22
|
+
if Feature.enabled?(env_var)
|
23
|
+
klass.send(enabled_symbol, *args)
|
24
|
+
else
|
25
|
+
klass.send(disabled_symbol, *args)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def register_instance_method(klass: nil, symbol: nil, disabled_symbol: nil, enabled_symbol: nil, env_var: nil)
|
31
|
+
return if klass.nil? || symbol.nil? || disabled_symbol.nil? || enabled_symbol.nil? || env_var.nil?
|
32
|
+
klass.send(:define_method, symbol.to_s) do |*args|
|
33
|
+
if Feature.enabled?(env_var)
|
34
|
+
send(enabled_symbol, *args)
|
35
|
+
else
|
36
|
+
send(disabled_symbol, *args)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
@features = {}
|
43
|
+
|
44
|
+
attr_reader :env_var, :description
|
45
|
+
def initialize(env_var: nil, description: nil)
|
46
|
+
raise "Invalid Feature" if env_var.nil? || description.nil?
|
47
|
+
@env_var = env_var
|
48
|
+
@description = description
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module PantographCore
|
2
|
+
class Globals
|
3
|
+
def self.captured_output
|
4
|
+
@captured_output ||= ""
|
5
|
+
end
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_writer(:captured_output)
|
9
|
+
attr_writer(:capture_output)
|
10
|
+
attr_writer(:verbose)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.capture_output?
|
14
|
+
return nil unless @capture_output
|
15
|
+
return true
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.captured_output?
|
19
|
+
@capture_output && @captured_output.to_s.length > 0
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.verbose?
|
23
|
+
return nil unless @verbose
|
24
|
+
return true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|