77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
# File 'pantograph/lib/pantograph/commands_generator.rb', line 77
def run
program :name, 'pantograph'
program :version, Pantograph::VERSION
program :description, [
"CLI for 'pantograph' - #{Pantograph::DESCRIPTION}\n",
"\tRun using `pantograph [platform] [lane_name]`",
"\tTo pass values to the lanes use `pantograph [platform] [lane_name] key:value key2:value2`"
].join("\n")
program :help, 'Author', 'Felix Krause <[email protected]>'
program :help, 'Website', 'https://pantograph.tools'
program :help, 'GitHub', 'https://github.com/johnknapprs/pantograph'
program :help_formatter, :compact
global_option('--verbose') { PantographCore::Globals.verbose = true }
global_option('--capture_output', 'Captures the output of the current run, and generates a markdown issue template') do
PantographCore::Globals.capture_output = false
PantographCore::Globals.verbose = true
end
global_option('--troubleshoot', 'Enables extended verbose mode. Use with caution, as this even includes ALL sensitive data. Cannot be used on CI.')
always_trace!
command :trigger do |c|
c.syntax = 'pantograph [lane]'
c.description = 'Run a specific lane. Pass the lane name and optionally the platform first.'
c.option('--env STRING[,STRING2]', String, 'Add environment(s) to use with `dotenv`')
c.action do |args, options|
if ensure_pantfile
Pantograph::CommandLineHandler.handle(args, options)
end
end
end
command :init do |c|
c.syntax = 'pantograph init'
c.description = 'Helps you with your initial pantograph setup'
c.action do |args, options|
Pantograph::Setup.start
end
end
command :new_action do |c|
c.syntax = 'pantograph new_action'
c.description = 'Create a new custom action for pantograph.'
c.option('--name STRING', String, 'Name of your new action')
c.action do |args, options|
Pantograph::NewAction.run(new_action_name: options.name)
end
end
command :socket_server do |c|
c.syntax = 'pantograph start_server'
c.description = 'Starts local socket server and enables only a single local connection'
c.option('-s', '--stay_alive', 'Keeps socket server up even after error or disconnects, requires CTRL-C to kill.')
c.option('-c seconds', '--connection_timeout', 'Sets connection established timeout')
c.action do |args, options|
default_connection_timeout = 5
stay_alive = options.stay_alive || false
connection_timeout = options.connection_timeout || default_connection_timeout
if stay_alive && options.connection_timeout.nil?
UI.important("stay_alive is set, but the connection timeout is not, this will give you #{default_connection_timeout} seconds to (re)connect")
end
require 'pantograph/server/socket_server'
require 'pantograph/server/socket_server_action_command_executor'
command_executor = SocketServerActionCommandExecutor.new
server = Pantograph::SocketServer.new(
command_executor: command_executor,
connection_timeout: connection_timeout,
stay_alive: stay_alive
)
result = server.start
UI.success("Result: #{result}") if result
end
end
command :lanes do |c|
c.syntax = 'pantograph lanes'
c.description = 'Lists all available lanes and shows their description'
c.option("-j", "--json", "Output the lanes in JSON instead of text")
c.action do |args, options|
if options.json || ensure_pantfile
require 'pantograph/lane_list'
path = PantographCore::PantographFolder.pantfile_path
if options.json
Pantograph::LaneList.output_json(path)
else
Pantograph::LaneList.output(path)
end
end
end
end
command :list do |c|
c.syntax = 'pantograph list'
c.description = 'Lists all available lanes without description'
c.action do |args, options|
if ensure_pantfile
ff = Pantograph::PantFile.new(PantographCore::PantographFolder.pantfile_path)
UI.message("Available lanes:")
ff.runner.available_lanes.each do |lane|
UI.message("- #{lane}")
end
UI.important("Execute using `pantograph [lane_name]`")
end
end
end
command :docs do |c|
c.syntax = 'pantograph docs'
c.description = 'Generate a markdown based documentation based on the Pantfile'
c.option('-f', '--force', 'Overwrite the existing README.md in the ./pantograph folder')
c.action do |args, options|
if ensure_pantfile
ff = Pantograph::PantFile.new(File.join(PantographCore::PantographFolder.path || '.', 'Pantfile'))
UI.message("You don't need to run `pantograph docs` manually any more, this will be done automatically for you when running a lane.")
Pantograph::DocsGenerator.run(ff)
end
end
end
command :run do |c|
c.syntax = 'pantograph run [action] key1:value1 key2:value2'
c.description = 'Run a pantograph one-off action without a full lane'
c.action do |args, options|
require 'pantograph/one_off'
result = Pantograph::OneOff.execute(args: args)
UI.success("Result: #{result}") if result
end
end
command :actions do |c|
c.syntax = 'pantograph actions'
c.description = 'Lists all available pantograph actions'
c.option('--platform STRING', String, 'Only show actions available on the given platform')
c.action do |args, options|
require 'pantograph/documentation/actions_list'
Pantograph::ActionsList.run(filter: args.first, platform: options.platform)
end
end
command :action do |c|
c.syntax = 'pantograph action [tool_name]'
c.description = 'Shows more information for a specific command'
c.action do |args, options|
require 'pantograph/documentation/actions_list'
Pantograph::ActionsList.run(filter: args.first)
end
end
command :enable_auto_complete do |c|
c.syntax = 'pantograph enable_auto_complete'
c.description = 'Enable tab auto completion'
c.option('-c STRING[,STRING2]', '--custom STRING[,STRING2]', String, 'Add custom command(s) for which tab auto complete should be enabled too')
c.action do |args, options|
require 'pantograph/auto_complete'
Pantograph::AutoComplete.execute(args, options)
end
end
command :env do |c|
c.syntax = 'pantograph env'
c.description = 'Print your pantograph environment, use this when you submit an issue on GitHub'
c.action do |args, options|
require "pantograph/environment_printer"
Pantograph::EnvironmentPrinter.output
end
end
command :update_pantograph do |c|
c.syntax = 'pantograph update_pantograph'
c.description = 'Update pantograph to the latest release'
c.action do |args, options|
require 'pantograph/one_off'
Pantograph::OneOff.run(action: "update_pantograph", parameters: {})
end
end
command :new_plugin do |c|
c.syntax = 'pantograph new_plugin [plugin_name]'
c.description = 'Create a new plugin that can be used with pantograph'
c.action do |args, options|
PluginGenerator.new.generate(args.shift)
end
end
command :add_plugin do |c|
c.syntax = 'pantograph add_plugin [plugin_name]'
c.description = 'Add a new plugin to your pantograph setup'
c.action do |args, options|
args << UI.input("Enter the name of the plugin to install: ") if args.empty?
args.each do |plugin_name|
Pantograph.plugin_manager.add_dependency(plugin_name)
end
UI.important("Make sure to commit your Gemfile, Gemfile.lock and #{PluginManager::PLUGINFILE_NAME} to version control")
Pantograph.plugin_manager.install_dependencies!
end
end
command :install_plugins do |c|
c.syntax = 'pantograph install_plugins'
c.description = 'Install all plugins for this project'
c.action do |args, options|
Pantograph.plugin_manager.install_dependencies!
end
end
command :update_plugins do |c|
c.syntax = 'pantograph update_plugins'
c.description = 'Update all plugin dependencies'
c.action do |args, options|
Pantograph.plugin_manager.update_dependencies!
end
end
command :search_plugins do |c|
c.syntax = 'pantograph search_plugins [search_query]'
c.description = 'Search for plugins, search query is optional'
c.action do |args, options|
search_query = args.last
PluginSearch.print_plugins(search_query: search_query)
end
end
default_command(:trigger)
run!
end
|