Class: EY::CLI
- Inherits:
-
Thor
show all
- Includes:
- Thor::Actions
- Defined in:
- lib/engineyard/cli.rb,
lib/engineyard/cli/ui.rb,
lib/engineyard/cli/api.rb,
lib/engineyard/cli/web.rb,
lib/engineyard/cli/recipes.rb
Defined Under Namespace
Classes: API, Recipes, UI, Web
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
14
15
16
17
18
|
# File 'lib/engineyard/cli.rb', line 14
def self.start(*)
Thor::Base.shell = EY::CLI::UI
EY.ui = EY::CLI::UI.new
super
end
|
Instance Method Details
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/engineyard/cli.rb', line 52
def deploy
app, environment = fetch_app_and_environment(options[:app], options[:environment], options[:account])
environment.ignore_bad_master = options[:ignore_bad_master]
deploy_ref = if options[:app]
environment.resolve_branch(options[:ref], options[:ignore_default_branch]) ||
raise(EY::Error, "When specifying the application, you must also specify the ref to deploy\nUsage: ey deploy --app <app name> --ref <branch|tag|ref>")
else
environment.resolve_branch(options[:ref], options[:ignore_default_branch]) ||
repo.current_branch ||
raise(DeployArgumentError)
end
EY.ui.info "Beginning deploy for '#{app.name}' in '#{environment.name}' on server..."
deploy_options = {'extras' => options[:extra_deploy_hook_options]}
if options.has_key?('migrate') deploy_options['migrate'] = options['migrate'].respond_to?(:to_str) ? options['migrate'] : !!options['migrate']
end
deploy_options['verbose'] = options['verbose'] if options.has_key?('verbose')
if environment.deploy(app, deploy_ref, deploy_options)
EY.ui.info "Deploy complete"
EY.ui.info "Now you can run `ey launch' to open the application in a browser."
else
raise EY::Error, "Deploy failed"
end
rescue NoEnvironmentError => e
exists = api.environments.named(options[:environment])
raise exists ? EnvironmentUnlinkedError.new(options[:environment]) : e
end
|
#environments ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/engineyard/cli.rb', line 115
def environments
if options[:all] && options[:simple]
puts api.environments.map {|env| env.name}
elsif options[:all]
EY.ui.print_envs(api.apps, EY.config.default_environment, options[:simple])
else
apps = api.apps_for_repo(repo)
if apps.size > 1
message = "This git repo matches multiple Applications in AppCloud:\n"
apps.each { |app| message << "\t#{app.name}\n" }
message << "The following environments contain those applications:\n\n"
EY.ui.warn(message)
elsif apps.empty?
EY.ui.warn(NoAppError.new(repo).message + "\nUse #{self.class.send(:banner_base)} environments --all to see all environments.")
end
EY.ui.print_envs(apps, EY.config.default_environment, options[:simple])
end
end
|
#help(*cmds) ⇒ Object
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
329
330
331
332
333
334
335
336
337
|
# File 'lib/engineyard/cli.rb', line 295
def help(*cmds)
if cmds.empty?
base = self.class.send(:banner_base)
list = self.class.printable_tasks
EY.ui.say "Usage:"
EY.ui.say " #{base} [--help] [--version] COMMAND [ARGS]"
EY.ui.say
EY.ui.say "Deploy commands:"
deploy_cmds = %w(deploy environments logs rebuild rollback status)
deploy_cmds.map! do |name|
list.find{|task| task[0] =~ /^#{base} #{name}/ }
end
list -= deploy_cmds
EY.ui.print_help(deploy_cmds)
EY.ui.say
self.class.subcommands.each do |name|
klass = self.class.subcommand_class_for(name)
list.reject!{|cmd| cmd[0] =~ /^#{base} #{name}/}
EY.ui.say "#{name.capitalize} commands:"
tasks = klass.printable_tasks.reject{|t| t[0] =~ /help$/ }
EY.ui.print_help(tasks)
EY.ui.say
end
%w(help version).each{|n| list.reject!{|c| c[0] =~ /^#{base} #{n}/ } }
if list.any?
EY.ui.say "Other commands:"
EY.ui.print_help(list)
EY.ui.say
end
self.class.send(:class_options_help, shell)
EY.ui.say "See '#{base} help COMMAND' for more information on a specific command."
elsif klass = self.class.subcommand_class_for(cmds.first)
klass.new.help(*cmds[1..-1])
else
super
end
end
|
344
345
346
347
|
# File 'lib/engineyard/cli.rb', line 344
def launch
environment = fetch_environment(options[:environment], options[:account])
environment.launch
end
|
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
# File 'lib/engineyard/cli.rb', line 265
def logs
environment = fetch_environment(options[:environment], options[:account])
environment.logs.each do |log|
EY.ui.info log.instance_name
if log.main
EY.ui.info "Main logs for #{environment.name}:"
EY.ui.say log.main
end
if log.custom
EY.ui.info "Custom logs for #{environment.name}:"
EY.ui.say log.custom
end
end
end
|
153
154
155
156
157
|
# File 'lib/engineyard/cli.rb', line 153
def rebuild
environment = fetch_environment(options[:environment], options[:account])
EY.ui.debug("Rebuilding #{environment.name}")
environment.rebuild
end
|
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/engineyard/cli.rb', line 176
def rollback
app, environment = fetch_app_and_environment(options[:app], options[:environment], options[:account])
EY.ui.info("Rolling back '#{app.name}' in '#{environment.name}'")
if environment.rollback(app, options[:extra_deploy_hook_options], options[:verbose])
EY.ui.info "Rollback complete"
else
raise EY::Error, "Rollback failed"
end
end
|
#ssh(cmd = nil) ⇒ Object
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/engineyard/cli.rb', line 215
def ssh(cmd=nil)
environment = fetch_environment(options[:environment], options[:account])
hosts = ssh_hosts(options, environment)
raise NoCommandError.new if cmd.nil? and hosts.size != 1
hosts.each do |host|
system Escape.shell_command(['ssh', "#{environment.username}@#{host}", cmd].compact)
end
end
|
97
98
99
100
101
102
103
104
105
|
# File 'lib/engineyard/cli.rb', line 97
def status
app, environment = fetch_app_and_environment(options[:app], options[:environment], options[:account])
deployment = app.last_deployment_on(environment)
if deployment
EY.ui.show_deployment(deployment)
else
raise EY::Error, "Application #{app.name} hass not been deployed on #{environment.name}."
end
end
|
289
290
291
|
# File 'lib/engineyard/cli.rb', line 289
def version
EY.ui.say %{engineyard version #{EY::VERSION}}
end
|
350
351
352
353
|
# File 'lib/engineyard/cli.rb', line 350
def whoami
user = api.user
EY.ui.say "#{user.name} (#{user.email})"
end
|