5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/aptible/cli/subcommands/apps.rb', line 5
def self.included(thor)
thor.class_eval do
include Helpers::Account
include Helpers::Token
desc 'apps', 'List all applications'
option :account
def apps
if options[:account]
accounts = [account_from_handle(options[:account])]
else
accounts = Aptible::Api::Account.all(token: fetch_token)
end
accounts.each do |account|
say "=== #{account.handle}"
account.apps.each do |app|
say app.handle
end
say ''
end
end
desc 'apps:create HANDLE', 'Create a new application'
option :account
define_method 'apps:create' do |handle|
account = ensure_account(options)
app = account.create_app(handle: handle)
if app.errors.any?
fail Thor::Error, app.errors.full_messages.first
else
say "App #{handle} created!"
end
end
desc 'apps:scale TYPE NUMBER', 'Scale app to NUMBER of instances'
option :app
option :account
define_method 'apps:scale' do |type, n|
num = Integer(n)
app = ensure_app(options)
service = app.services.find { |s| s.process_type == type }
op = service.create_operation(type: 'scale', container_count: num)
poll_for_success(op)
say "Scaled #{app.handle} to #{num} instances."
end
end
end
|