shelly 0.0.57 → 0.0.58

Sign up to get free protection for your applications and to get access to all the features.
data/Guardfile CHANGED
@@ -1,5 +1,6 @@
1
1
  guard 'rspec', :cli => '--color --format doc' do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
+ watch('lib/shelly/helpers.rb') { "spec" }
3
4
  watch(%r{^lib/shelly/(.+)\.rb$}) { |m| "spec/shelly/#{m[1]}_spec.rb" }
4
5
  watch('spec/spec_helper.rb') { "spec" }
5
6
  end
@@ -9,14 +9,13 @@ module Shelly
9
9
  include Helpers
10
10
 
11
11
  before_hook :logged_in?, :only => [:list, :get, :create, :restore]
12
- before_hook :cloudfile_present?, :only => [:list]
13
12
 
14
13
  class_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
15
14
 
16
15
  desc "list", "List available database backups"
17
16
  def list
18
- multiple_clouds(options[:cloud], "backup list")
19
- backups = @app.database_backups
17
+ app = multiple_clouds(options[:cloud], "backup list")
18
+ backups = app.database_backups
20
19
  if backups.present?
21
20
  to_display = [["Filename", "| Size"]]
22
21
  backups.each do |backup|
@@ -31,7 +30,7 @@ module Shelly
31
30
  end
32
31
  rescue Client::NotFoundException => e
33
32
  raise unless e.resource == :cloud
34
- say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
33
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
35
34
  end
36
35
 
37
36
  desc "get [FILENAME]", "Download database backup"
@@ -40,9 +39,9 @@ module Shelly
40
39
  If filename is not specyfied, latest database backup will be downloaded.
41
40
  }
42
41
  def get(handler = "last")
43
- multiple_clouds(options[:cloud], "backup get #{handler}")
42
+ app = multiple_clouds(options[:cloud], "backup get #{handler}")
44
43
 
45
- backup = @app.database_backup(handler)
44
+ backup = app.database_backup(handler)
46
45
  bar = Shelly::DownloadProgressBar.new(backup.size)
47
46
  backup.download(bar.progress_callback)
48
47
 
@@ -51,7 +50,7 @@ module Shelly
51
50
  rescue Client::NotFoundException => e
52
51
  case e.resource
53
52
  when :cloud
54
- say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
53
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
55
54
  when :database_backup
56
55
  say_error "Backup not found", :with_exit => false
57
56
  say "You can list available backups with `shelly backup list` command"
@@ -65,31 +64,31 @@ module Shelly
65
64
  If database kind is not specified, backup of all configured databases will be performed.
66
65
  }
67
66
  def create(kind = nil)
68
- multiple_clouds(options[:cloud], "backup create [DB_KIND]")
69
- @app.request_backup(kind)
67
+ app = multiple_clouds(options[:cloud], "backup create [DB_KIND]")
68
+ app.request_backup(kind)
70
69
  say "Backup requested. It can take up to several minutes for " +
71
70
  "the backup process to finish and the backup to show up in backups list.", :green
72
71
  rescue Client::ValidationException => e
73
72
  say_error e[:message]
74
73
  rescue Client::NotFoundException => e
75
74
  raise unless e.resource == :cloud
76
- say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
75
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
77
76
  end
78
77
 
79
78
  desc "restore FILENAME", "Restore database to state from given backup"
80
79
  def restore(filename)
81
- multiple_clouds(options[:cloud], "backup restore FILENAME")
82
- backup = @app.database_backup(filename)
80
+ app = multiple_clouds(options[:cloud], "backup restore FILENAME")
81
+ backup = app.database_backup(filename)
83
82
  say "You are about restore database #{backup.kind} for cloud #{backup.code_name} to state from #{backup.filename}"
84
83
  say_new_line
85
84
  ask_to_restore_database
86
- @app.restore_backup(filename)
85
+ app.restore_backup(filename)
87
86
  say_new_line
88
87
  say "Restore has been scheduled. Wait a few minutes till database is restored."
89
88
  rescue Client::NotFoundException => e
90
89
  case e.resource
91
90
  when :cloud
92
- say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
91
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
93
92
  when :database_backup
94
93
  say_error "Backup not found", :with_exit => false
95
94
  say "You can list available backups with `shelly backup list` command"
@@ -6,98 +6,87 @@ module Shelly
6
6
  include Thor::Actions
7
7
  include Helpers
8
8
 
9
- before_hook :logged_in?, :only => [:list, :show, :create, :edit, :delete]
10
- before_hook :cloudfile_present?, :only => [:list, :show, :create, :edit, :delete]
9
+ before_hook :logged_in?, :only => [:list, :show, :create, :new, :edit, :update, :delete]
10
+ class_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
11
11
 
12
12
  desc "list", "List configuration files"
13
13
  def list
14
- cloudfile = Cloudfile.new
15
- cloudfile.clouds.each do |cloud|
16
- @app = App.new(cloud)
17
- begin
18
- configs = @app.configs
19
- unless configs.empty?
20
- say "Configuration files for #{cloud}", :green
21
- user_configs = @app.user_configs
22
- unless user_configs.empty?
23
- say "Custom configuration files:"
24
- print_configs(user_configs)
25
- else
26
- say "You have no custom configuration files."
27
- end
28
- shelly_configs = @app.shelly_generated_configs
29
- unless shelly_configs.empty?
30
- say "Following files are created by Shelly Cloud:"
31
- print_configs(shelly_configs)
32
- end
33
- else
34
- say "Cloud #{cloud} has no configuration files"
35
- end
36
- rescue Client::NotFoundException => e
37
- raise unless e.resource == :cloud
38
- say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
14
+ app = multiple_clouds(options[:cloud], "list")
15
+ configs = app.configs
16
+ unless configs.empty?
17
+ say "Configuration files for #{app}", :green
18
+ user_configs = app.user_configs
19
+ unless user_configs.empty?
20
+ say "Custom configuration files:"
21
+ print_configs(user_configs)
22
+ else
23
+ say "You have no custom configuration files."
39
24
  end
25
+ shelly_configs = app.shelly_generated_configs
26
+ unless shelly_configs.empty?
27
+ say "Following files are created by Shelly Cloud:"
28
+ print_configs(shelly_configs)
29
+ end
30
+ else
31
+ say "Cloud #{cloud} has no configuration files"
40
32
  end
33
+ rescue Client::NotFoundException => e
34
+ raise unless e.resource == :cloud
35
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
41
36
  end
42
37
 
43
- # FIXME: Check if path argument is present via Thor (mandatory arguments)
44
- method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
45
38
  desc "show PATH", "View configuration file"
46
- def show(path = nil)
47
- say_error "No configuration file specified" unless path
48
- multiple_clouds(options[:cloud], "show #{path}")
49
- config = @app.config(path)
39
+ def show(path)
40
+ app = multiple_clouds(options[:cloud], "show #{path}")
41
+ config = app.config(path)
50
42
  say "Content of #{config["path"]}:", :green
51
43
  say config["content"]
52
44
  rescue Client::NotFoundException => e
53
45
  case e.resource
54
46
  when :cloud
55
- say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
47
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
56
48
  when :config
57
49
  say_error "Config '#{path}' not found", :with_exit => false
58
- say_error "You can list available config files with `shelly config list --cloud #{@app}`"
50
+ say_error "You can list available config files with `shelly config list --cloud #{app}`"
59
51
  else raise
60
52
  end
61
53
  end
62
54
 
63
55
  map "new" => :create
64
- method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
65
56
  desc "create PATH", "Create configuration file"
66
- def create(path = nil)
67
- say_error "No path specified" unless path
57
+ def create(path)
68
58
  output = open_editor(path)
69
- multiple_clouds(options[:cloud], "create #{path}")
70
- @app.create_config(path, output)
59
+ app = multiple_clouds(options[:cloud], "create #{path}")
60
+ app.create_config(path, output)
71
61
  say "File '#{path}' created.", :green
72
62
  say "To make changes to running application redeploy it using:"
73
- say "`shelly redeploy --cloud #{@app}`"
63
+ say "`shelly redeploy --cloud #{app}`"
74
64
  rescue Client::NotFoundException => e
75
65
  raise unless e.resource == :cloud
76
- say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
66
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
77
67
  rescue Client::ValidationException => e
78
68
  e.each_error { |error| say_error error, :with_exit => false }
79
69
  exit 1
80
70
  end
81
71
 
82
72
  map "update" => :edit
83
- method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
84
73
  desc "edit PATH", "Edit configuration file"
85
74
  def edit(path = nil)
86
75
  say_error "No configuration file specified" unless path
87
- multiple_clouds(options[:cloud], "edit #{path}")
88
- config = @app.config(path)
76
+ app = multiple_clouds(options[:cloud], "edit #{path}")
77
+ config = app.config(path)
89
78
  content = open_editor(config["path"], config["content"])
90
- @app.update_config(path, content)
79
+ app.update_config(path, content)
91
80
  say "File '#{config["path"]}' updated.", :green
92
81
  say "To make changes to running application redeploy it using:"
93
- say "`shelly redeploy --cloud #{@app}`"
82
+ say "`shelly redeploy --cloud #{app}`"
94
83
  rescue Client::NotFoundException => e
95
84
  case e.resource
96
85
  when :cloud
97
- say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
86
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
98
87
  when :config
99
88
  say_error "Config '#{path}' not found", :with_exit => false
100
- say_error "You can list available config files with `shelly config list --cloud #{@app}`"
89
+ say_error "You can list available config files with `shelly config list --cloud #{app}`"
101
90
  else raise
102
91
  end
103
92
  rescue Client::ValidationException => e
@@ -105,27 +94,26 @@ module Shelly
105
94
  exit 1
106
95
  end
107
96
 
108
- method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
109
97
  desc "delete PATH", "Delete configuration file"
110
98
  def delete(path = nil)
111
99
  say_error "No configuration file specified" unless path
112
- multiple_clouds(options[:cloud], "delete #{path}")
100
+ app = multiple_clouds(options[:cloud], "delete #{path}")
113
101
  answer = yes?("Are you sure you want to delete 'path' (yes/no): ")
114
102
  if answer
115
- @app.delete_config(path)
103
+ app.delete_config(path)
116
104
  say "File '#{path}' deleted.", :green
117
105
  say "To make changes to running application redeploy it using:"
118
- say "`shelly redeploy --cloud #{@app}`"
106
+ say "`shelly redeploy --cloud #{app}`"
119
107
  else
120
108
  say "File not deleted"
121
109
  end
122
110
  rescue Client::NotFoundException => e
123
111
  case e.resource
124
112
  when :cloud
125
- say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
113
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
126
114
  when :config
127
115
  say_error "Config '#{path}' not found", :with_exit => false
128
- say_error "You can list available config files with `shelly config list --cloud #{@app}`"
116
+ say_error "You can list available config files with `shelly config list --cloud #{app}`"
129
117
  else raise
130
118
  end
131
119
  end
@@ -8,13 +8,12 @@ module Shelly
8
8
  include Helpers
9
9
 
10
10
  before_hook :logged_in?, :only => [:list, :show]
11
- before_hook :cloudfile_present?, :only => [:list, :show]
11
+ class_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
12
12
 
13
13
  desc "list", "Lists deploy logs"
14
- method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
15
14
  def list
16
- multiple_clouds(options[:cloud], "deploys list")
17
- logs = @app.deploy_logs
15
+ app = multiple_clouds(options[:cloud], "deploys list")
16
+ logs = app.deploy_logs
18
17
  unless logs.empty?
19
18
  say "Available deploy logs", :green
20
19
  logs.each do |log|
@@ -25,15 +24,14 @@ module Shelly
25
24
  end
26
25
  rescue Client::NotFoundException => e
27
26
  raise unless e.resource == :cloud
28
- say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
27
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
29
28
  end
30
29
 
31
30
  desc "show LOG", "Show specific deploy log"
32
- method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
33
31
  def show(log = nil)
34
32
  specify_log(log)
35
- multiple_clouds(options[:cloud], "deploys show #{log}")
36
- content = @app.deploy_log(log)
33
+ app = multiple_clouds(options[:cloud], "deploys show #{log}")
34
+ content = app.deploy_log(log)
37
35
  say "Log for deploy done on #{content["created_at"]}", :green
38
36
  if content["bundle_install"]
39
37
  say("Starting bundle install", :green); say(content["bundle_install"])
@@ -53,9 +51,9 @@ module Shelly
53
51
  rescue Client::NotFoundException => e
54
52
  case e.resource
55
53
  when :cloud
56
- say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
54
+ say_error "You have no access to '#{app.code_name}' cloud defined in Cloudfile"
57
55
  when :log
58
- say_error "Log not found, list all deploy logs using `shelly deploys list --cloud=#{@app.code_name}`"
56
+ say_error "Log not found, list all deploy logs using `shelly deploys list --cloud=#{app.code_name}`"
59
57
  else raise
60
58
  end
61
59
  end
@@ -18,7 +18,6 @@ module Shelly
18
18
  # FIXME: it should be possible to pass single symbol, instead of one element array
19
19
  before_hook :logged_in?, :only => [:add, :status, :list, :start, :stop, :logs, :delete, :ip, :logout, :execute, :rake, :setup]
20
20
  before_hook :inside_git_repository?, :only => [:add, :setup]
21
- before_hook :cloudfile_present?, :only => [:logs, :stop, :start, :ip, :execute, :rake, :setup]
22
21
 
23
22
  map %w(-v --version) => :version
24
23
  desc "version", "Display shelly version"
@@ -79,39 +78,38 @@ module Shelly
79
78
  desc "add", "Add a new cloud"
80
79
  def add
81
80
  check_options(options)
82
- @app = Shelly::App.new
83
- @app.code_name = options["code-name"] || ask_for_code_name
84
- @app.databases = options["databases"] || ask_for_databases
85
- @app.size = options["size"] || "large"
86
- @app.create
87
-
88
- if overwrite_remote?(@app)
89
- say "Adding remote #{@app} #{@app.git_url}", :green
90
- @app.add_git_remote
81
+ app = Shelly::App.new
82
+ app.code_name = options["code-name"] || ask_for_code_name
83
+ app.databases = options["databases"] || ask_for_databases
84
+ app.size = options["size"] || "large"
85
+ app.create
86
+
87
+ if overwrite_remote?(app)
88
+ say "Adding remote #{app} #{app.git_url}", :green
89
+ app.add_git_remote
91
90
  else
92
91
  say "You have to manually add git remote:"
93
- say "`git remote add NAME #{@app.git_url}`"
92
+ say "`git remote add NAME #{app.git_url}`"
94
93
  end
95
94
 
96
95
  say "Creating Cloudfile", :green
97
- @app.create_cloudfile
98
- if @app.attributes["trial"]
96
+ app.create_cloudfile
97
+ if app.attributes["trial"]
99
98
  say_new_line
100
99
  say "Billing information", :green
101
100
  say "Cloud created with 20 Euro credit."
102
101
  say "Remember to provide billing details before trial ends."
103
- url = "#{@app.shelly.shellyapp_url}/apps/#{@app}/billing/edit"
104
- say url
102
+ say app.edit_billing_url
105
103
  end
106
104
 
107
105
  info_adding_cloudfile_to_repository
108
- info_deploying_to_shellycloud(@app)
106
+ info_deploying_to_shellycloud(app)
109
107
 
110
108
  rescue Client::ValidationException => e
111
109
  e.each_error { |error| say_error error, :with_exit => false }
112
110
  say_new_line
113
111
  say_error "Fix erros in the below command and type it again to create your cloud" , :with_exit => false
114
- say_error "shelly add --code-name=#{@app.code_name} --databases=#{@app.databases.join(',')} --size=#{@app.size}"
112
+ say_error "shelly add --code-name=#{app.code_name} --databases=#{app.databases.join(',')} --size=#{app.size}"
115
113
  end
116
114
 
117
115
  desc "list", "List available clouds"
@@ -134,146 +132,136 @@ module Shelly
134
132
  end
135
133
 
136
134
  map "status" => :list
137
-
135
+ method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
138
136
  desc "ip", "List cloud's IP addresses"
139
137
  def ip
140
- @cloudfile = Cloudfile.new
141
- @cloudfile.clouds.each do |cloud|
142
- begin
143
- @app = App.new(cloud)
144
- say "Cloud #{cloud}:", :green
145
- print_wrapped "Web server IP: #{@app.web_server_ip}", :ident => 2
146
- print_wrapped "Mail server IP: #{@app.mail_server_ip}", :ident => 2
147
- rescue Client::NotFoundException => e
148
- raise unless e.resource == :cloud
149
- say_error "You have no access to '#{cloud}' cloud defined in Cloudfile", :with_exit => false
150
- end
151
- end
138
+ app = multiple_clouds(options[:cloud], "ip")
139
+ web_server_ip = app.web_server_ip
140
+ say "Cloud #{app}:", :green
141
+ print_wrapped "Web server IP: #{web_server_ip}", :ident => 2
142
+ print_wrapped "Mail server IP: #{app.mail_server_ip}", :ident => 2
143
+ rescue Client::NotFoundException => e
144
+ raise unless e.resource == :cloud
145
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
152
146
  end
153
147
 
154
148
  desc "start", "Start the cloud"
155
149
  method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
156
150
  def start
157
- multiple_clouds(options[:cloud], "start")
158
- @app.start
159
- say "Starting cloud #{@app}.", :green
151
+ app = multiple_clouds(options[:cloud], "start")
152
+ app.start
153
+ say "Starting cloud #{app}.", :green
160
154
  say "This can take up to 10 minutes."
161
155
  say "Check status with: `shelly list`"
162
156
  rescue Client::ConflictException => e
163
157
  case e[:state]
164
158
  when "running"
165
- say_error "Not starting: cloud '#{@app}' is already running"
159
+ say_error "Not starting: cloud '#{app}' is already running"
166
160
  when "deploying", "configuring"
167
- say_error "Not starting: cloud '#{@app}' is currently deploying"
161
+ say_error "Not starting: cloud '#{app}' is currently deploying"
168
162
  when "no_code"
169
163
  say_error "Not starting: no source code provided", :with_exit => false
170
164
  say_error "Push source code using:", :with_exit => false
171
- say " git push #{@app} master"
165
+ say " git push #{app} master"
172
166
  when "deploy_failed", "configuration_failed"
173
167
  say_error "Not starting: deployment failed", :with_exit => false
174
168
  say_error "Support has been notified", :with_exit => false
175
- say_error "Check `shelly deploys show last --cloud #{@app}` for reasons of failure"
169
+ say_error "Check `shelly deploys show last --cloud #{app}` for reasons of failure"
176
170
  when "not_enough_resources"
177
171
  say_error %{Sorry, There are no resources for your servers.
178
172
  We have been notified about it. We will be adding new resources shortly}
179
173
  when "no_billing"
180
- say_error "Please fill in billing details to start #{@app}.", :with_exit => false
181
- say_error "Visit: #{@app.edit_billing_url}", :with_exit => false
174
+ say_error "Please fill in billing details to start #{app}.", :with_exit => false
175
+ say_error "Visit: #{app.edit_billing_url}", :with_exit => false
182
176
  when "payment_declined"
183
- say_error "Not starting. Invoice for cloud '#{@app}' was declined."
177
+ say_error "Not starting. Invoice for cloud '#{app}' was declined."
184
178
  end
185
179
  exit 1
186
180
  rescue Client::NotFoundException => e
187
181
  raise unless e.resource == :cloud
188
- say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
182
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
189
183
  end
190
184
 
191
185
  desc "setup", "Set up clouds"
186
+ method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
192
187
  def setup
193
- say "Investigating Cloudfile"
194
- cloudfile = Cloudfile.new
195
- cloudfile.clouds.each do |cloud|
196
- begin
197
- app = App.new(cloud)
198
- say "Adding #{app} cloud", :green
199
- app.git_url = app.attributes["git_info"]["repository_url"]
200
- if overwrite_remote?(app)
201
- say "git remote add #{app} #{app.git_url}"
202
- app.add_git_remote
203
- say "git fetch production"
204
- app.git_fetch_remote
205
- say "git checkout -b #{app} --track #{app}/master"
206
- app.git_add_tracking_branch
207
- else
208
- say "You have to manually add remote:"
209
- say "`git remote add #{app} #{app.git_url}`"
210
- say "`git fetch production`"
211
- say "`git checkout -b #{app} --track #{app}/master`"
212
- end
213
-
214
- say_new_line
215
- rescue Client::NotFoundException => e
216
- raise unless e.resource == :cloud
217
- say_error "You have no access to '#{app}' cloud defined in Cloudfile"
218
- end
188
+ app = multiple_clouds(options[:cloud], "setup")
189
+ say "Setting up #{app} cloud", :green
190
+ app.git_url = app.attributes["git_info"]["repository_url"]
191
+ if overwrite_remote?(app)
192
+ say "git remote add #{app} #{app.git_url}"
193
+ app.add_git_remote
194
+ say "git fetch production"
195
+ app.git_fetch_remote
196
+ say "git checkout -b #{app} --track #{app}/master"
197
+ app.git_add_tracking_branch
198
+ else
199
+ say "You have to manually add remote:"
200
+ say "`git remote add #{app} #{app.git_url}`"
201
+ say "`git fetch production`"
202
+ say "`git checkout -b #{app} --track #{app}/master`"
219
203
  end
220
204
 
205
+ say_new_line
221
206
  say "Your application is set up.", :green
207
+ rescue Client::NotFoundException => e
208
+ raise unless e.resource == :cloud
209
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
222
210
  end
223
211
 
224
212
  desc "stop", "Shutdown the cloud"
225
213
  method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
226
214
  def stop
227
- multiple_clouds(options[:cloud], "stop")
215
+ app = multiple_clouds(options[:cloud], "stop")
228
216
  ask_to_stop_application
229
- @app.stop
217
+ app.stop
230
218
  say_new_line
231
- say "Cloud '#{@app}' stopped"
219
+ say "Cloud '#{app}' stopped"
232
220
  rescue Client::NotFoundException => e
233
221
  raise unless e.resource == :cloud
234
- say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
222
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
235
223
  end
236
224
 
237
225
  desc "delete", "Delete the cloud"
238
226
  method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
239
227
  def delete
240
- multiple_clouds(options[:cloud], "delete")
241
- say "You are about to delete application: #{@app}."
228
+ app = multiple_clouds(options[:cloud], "delete")
229
+ say "You are about to delete application: #{app}."
242
230
  say "Press Control-C at any moment to cancel."
243
231
  say "Please confirm each question by typing yes and pressing Enter."
244
232
  say_new_line
245
233
  ask_to_delete_files
246
234
  ask_to_delete_database
247
235
  ask_to_delete_application
248
- @app.delete
236
+ app.delete
249
237
  say_new_line
250
238
  say "Scheduling application delete - done"
251
239
  if App.inside_git_repository?
252
- @app.remove_git_remote
240
+ app.remove_git_remote
253
241
  say "Removing git remote - done"
254
242
  else
255
243
  say "Missing git remote"
256
244
  end
257
245
  rescue Client::NotFoundException => e
258
246
  raise unless e.resource == :cloud
259
- say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
247
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
260
248
  end
261
249
 
262
250
  desc "logs", "Show latest application logs"
263
251
  method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
264
252
  def logs
265
253
  cloud = options[:cloud]
266
- multiple_clouds(cloud, "logs")
254
+ app = multiple_clouds(cloud, "logs")
267
255
  begin
268
- logs = @app.application_logs
269
- say "Cloud #{@app}:", :green
256
+ logs = app.application_logs
257
+ say "Cloud #{app}:", :green
270
258
  logs.each_with_index do |log, i|
271
259
  say "Instance #{i+1}:", :green
272
260
  say log
273
261
  end
274
262
  rescue Client::NotFoundException => e
275
263
  raise unless e.resource == :cloud
276
- say_error "You have no access to '#{cloud || @app}' cloud defined in Cloudfile"
264
+ say_error "You have no access to '#{cloud || app}' cloud defined in Cloudfile"
277
265
  end
278
266
  end
279
267
 
@@ -291,15 +279,14 @@ We have been notified about it. We will be adding new resources shortly}
291
279
  If a file name is given, run contents of that file."
292
280
  }
293
281
  def execute(file_name_or_code)
294
- cloud = options[:cloud]
295
- multiple_clouds(cloud, "execute")
282
+ app = multiple_clouds(options[:cloud], "execute #{file_name_or_code}")
296
283
 
297
- result = @app.run(file_name_or_code)
284
+ result = app.run(file_name_or_code)
298
285
  say result
299
286
 
300
287
  rescue Client::APIException => e
301
288
  if e[:message] == "App not running"
302
- say_error "Cloud #{@app} is not running. Cannot run code."
289
+ say_error "Cloud #{app} is not running. Cannot run code."
303
290
  else
304
291
  raise
305
292
  end
@@ -309,34 +296,34 @@ We have been notified about it. We will be adding new resources shortly}
309
296
  method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
310
297
  def rake(task = nil)
311
298
  task = rake_args.join(" ")
312
- multiple_clouds(options[:cloud], "rake #{task}")
313
- result = @app.rake(task)
299
+ app = multiple_clouds(options[:cloud], "rake #{task}")
300
+ result = app.rake(task)
314
301
  say result
315
302
  rescue Client::APIException => e
316
303
  raise unless e[:message] == "App not running"
317
- say_error "Cloud #{@app} is not running. Cannot run rake task."
304
+ say_error "Cloud #{app} is not running. Cannot run rake task."
318
305
  end
319
306
 
320
307
  desc "redeploy", "Redeploy application"
321
308
  method_option :cloud, :type => :string, :aliases => "-c",
322
309
  :desc => "Specify which cloud to redeploy application for"
323
310
  def redeploy
324
- multiple_clouds(options[:cloud], "redeploy")
325
- @app.redeploy
326
- say "Redeploying your application for cloud '#{@app}'", :green
311
+ app = multiple_clouds(options[:cloud], "redeploy")
312
+ app.redeploy
313
+ say "Redeploying your application for cloud '#{app}'", :green
327
314
  rescue Client::ConflictException => e
328
315
  case e[:state]
329
316
  when "deploying", "configuring"
330
317
  say_error "Your application is being redeployed at the moment"
331
318
  when "no_code", "no_billing", "turned_off"
332
- say_error "Cloud #{@app} is not running", :with_exit => false
333
- say "Start your cloud with `shelly start --cloud #{@app}`"
319
+ say_error "Cloud #{app} is not running", :with_exit => false
320
+ say "Start your cloud with `shelly start --cloud #{app}`"
334
321
  exit 1
335
322
  else raise
336
323
  end
337
324
  rescue Client::NotFoundException => e
338
325
  raise unless e.resource == :cloud
339
- say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
326
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
340
327
  end
341
328
 
342
329
  # FIXME: move to helpers