shelly 0.0.43 → 0.0.44.pre

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.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@
4
4
  Gemfile.lock
5
5
  pkg/*
6
6
  .rvmrc
7
+ coverage
data/lib/shelly/app.rb CHANGED
@@ -94,6 +94,10 @@ module Shelly
94
94
  shelly.stop_cloud(code_name)
95
95
  end
96
96
 
97
+ def redeploy
98
+ shelly.redeploy(code_name)
99
+ end
100
+
97
101
  def cloudfile_path
98
102
  File.join(Dir.pwd, "Cloudfile")
99
103
  end
@@ -8,14 +8,14 @@ module Shelly
8
8
  namespace :backup
9
9
  include Helpers
10
10
 
11
- before_hook :logged_in?, :only => [:list, :get, :create]
11
+ before_hook :logged_in?, :only => [:list, :get, :create, :restore]
12
12
  before_hook :cloudfile_present?, :only => [:list]
13
13
 
14
- desc "list", "List database backups"
15
- method_option :cloud, :type => :string, :aliases => "-c",
16
- :desc => "Specify which cloud to list backups for"
14
+ class_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
15
+
16
+ desc "list", "List available database backups"
17
17
  def list
18
- multiple_clouds(options[:cloud], "backup list", "Select cloud to view database backups for using:")
18
+ multiple_clouds(options[:cloud], "backup list")
19
19
  backups = @app.database_backups
20
20
  if backups.present?
21
21
  to_display = [["Filename", "| Size"]]
@@ -29,18 +29,18 @@ module Shelly
29
29
  else
30
30
  say "No database backups available"
31
31
  end
32
- rescue Client::APIError => e
33
- if e.not_found?
34
- say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
35
- else
36
- raise e
37
- end
32
+ rescue Client::NotFoundException => e
33
+ raise unless e.resource == :cloud
34
+ say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
38
35
  end
39
36
 
40
- method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify which cloud list backups for"
41
- desc "get [FILENAME]", "Downloads specified or last backup to current directory"
37
+ desc "get [FILENAME]", "Download database backup"
38
+ long_desc %{
39
+ Download given database backup to current directory.
40
+ If filename is not specyfied, latest database backup will be downloaded.
41
+ }
42
42
  def get(handler = "last")
43
- multiple_clouds(options[:cloud], "backup get [FILENAME]", "Select cloud for which you want download backup")
43
+ multiple_clouds(options[:cloud], "backup get #{handler}")
44
44
 
45
45
  backup = @app.database_backup(handler)
46
46
  bar = Shelly::DownloadProgressBar.new(backup.size)
@@ -48,53 +48,52 @@ module Shelly
48
48
 
49
49
  say_new_line
50
50
  say "Backup file saved to #{backup.filename}", :green
51
- rescue Client::APIError => e
52
- case e.resource_not_found
51
+ rescue Client::NotFoundException => e
52
+ case e.resource
53
53
  when :cloud
54
- say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
55
- when :backup
54
+ say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
55
+ when :database_backup
56
56
  say_error "Backup not found", :with_exit => false
57
- say "You can list available backups with 'shelly backup list' command"
58
- else; raise e
57
+ say "You can list available backups with `shelly backup list` command"
58
+ else; raise
59
59
  end
60
60
  end
61
61
 
62
- desc "create [KIND]", "Creates current snapshot of given database. Default: all databases."
63
- method_option :cloud, :type => :string, :aliases => "-c",
64
- :desc => "Specify which cloud to create database snapshot for"
62
+ desc "create [DB_KIND]", "Create backup of given database"
63
+ long_desc %{
64
+ Create backup of given database.
65
+ If database kind is not specified, backup of all configured databases will be performed.
66
+ }
65
67
  def create(kind = nil)
66
- multiple_clouds(options[:cloud], "backup create", "Select cloud to create snapshot of database")
68
+ multiple_clouds(options[:cloud], "backup create [DB_KIND]")
67
69
  @app.request_backup(kind)
68
70
  say "Backup requested. It can take up to several minutes for " +
69
71
  "the backup process to finish and the backup to show up in backups list.", :green
70
- rescue Client::APIError => e
71
- if e.not_found?
72
- say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
73
- else
74
- say_error e.message
75
- end
72
+ rescue Client::ValidationException => e
73
+ say_error e[:message]
74
+ rescue Client::NotFoundException => e
75
+ raise unless e.resource == :cloud
76
+ say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
76
77
  end
77
78
 
78
- desc "restore <filename>", "Restore database to state from filename"
79
- method_option :cloud, :type => :string, :aliases => "-c",
80
- :desc => "Specify which cloud to restore database snapshot for"
81
- def restore(filename = nil)
82
- logged_in?
83
- multiple_clouds(options[:cloud], "backup restore <filename>", "Select cloud for which you want restore backup")
84
- say_error "Filename is required" unless filename
79
+ desc "restore FILENAME", "Restore database to state from given backup"
80
+ def restore(filename)
81
+ multiple_clouds(options[:cloud], "backup restore FILENAME")
85
82
  backup = @app.database_backup(filename)
86
83
  say "You are about restore database #{backup.kind} for cloud #{backup.code_name} to state from #{backup.filename}"
87
84
  say_new_line
88
85
  ask_to_restore_database
89
86
  @app.restore_backup(filename)
90
87
  say_new_line
91
- say "Restore has been scheduled. Wait few minutes till database is restored."
92
- rescue Client::APIError => e
93
- if e.not_found?
88
+ say "Restore has been scheduled. Wait a few minutes till database is restored."
89
+ rescue Client::NotFoundException => e
90
+ case e.resource
91
+ when :cloud
92
+ say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
93
+ when :database_backup
94
94
  say_error "Backup not found", :with_exit => false
95
- say "You can list available backups with 'shelly backup list' command"
96
- else
97
- raise e
95
+ say "You can list available backups with `shelly backup list` command"
96
+ else; raise
98
97
  end
99
98
  end
100
99
  end
@@ -33,88 +33,78 @@ module Shelly
33
33
  else
34
34
  say "Cloud #{cloud} has no configuration files"
35
35
  end
36
- rescue Client::APIError => e
37
- if e.resource_not_found == :cloud
38
- say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
39
- else
40
- raise e
41
- 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"
42
39
  end
43
40
  end
44
41
  end
45
42
 
46
- method_option :cloud, :type => :string, :aliases => "-c",
47
- :desc => "Specify which cloud to show configuration file for"
43
+ method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
48
44
  desc "show PATH", "View configuration file"
49
45
  def show(path = nil)
50
46
  say_error "No configuration file specified" unless path
51
- multiple_clouds(options[:cloud], "show #{path}", "Specify cloud using:")
47
+ multiple_clouds(options[:cloud], "show #{path}")
52
48
  config = @app.config(path)
53
49
  say "Content of #{config["path"]}:", :green
54
50
  say config["content"]
55
- rescue Client::APIError => e
56
- case e.resource_not_found
51
+ rescue Client::NotFoundException => e
52
+ case e.resource
57
53
  when :cloud
58
54
  say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
59
55
  when :config
60
56
  say_error "Config '#{path}' not found", :with_exit => false
61
57
  say_error "You can list available config files with `shelly config list --cloud #{@app}`"
62
- else; raise e
58
+ else raise
63
59
  end
64
60
  end
65
61
 
66
62
  map "new" => :create
67
- method_option :cloud, :type => :string, :aliases => "-c",
68
- :desc => "Specify which cloud to create configuration file for"
63
+ method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
69
64
  desc "create PATH", "Create configuration file"
70
65
  def create(path = nil)
71
66
  say_error "No path specified" unless path
72
67
  output = open_editor(path)
73
- multiple_clouds(options[:cloud], "create #{path}", "Specify cloud using:")
68
+ multiple_clouds(options[:cloud], "create #{path}")
74
69
  @app.create_config(path, output)
75
70
  say "File '#{path}' created, it will be used after next code deploy", :green
76
- rescue Client::APIError => e
77
- if e.resource_not_found == :cloud
78
- say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
79
- elsif e.validation?
80
- e.each_error { |error| say_error error, :with_exit => false }
81
- exit 1
82
- else
83
- say_error e.message
84
- end
71
+ rescue Client::NotFoundException => e
72
+ raise unless e.resource == :cloud
73
+ say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
74
+ rescue Client::ValidationException => e
75
+ e.each_error { |error| say_error error, :with_exit => false }
76
+ exit 1
85
77
  end
86
78
 
87
79
  map "update" => :edit
88
- method_option :cloud, :type => :string, :aliases => "-c",
89
- :desc => "Specify which cloud to edit configuration file for"
80
+ method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
90
81
  desc "edit PATH", "Edit configuration file"
91
82
  def edit(path = nil)
92
83
  say_error "No configuration file specified" unless path
93
- multiple_clouds(options[:cloud], "edit #{path}", "Specify cloud using:")
84
+ multiple_clouds(options[:cloud], "edit #{path}")
94
85
  config = @app.config(path)
95
86
  content = open_editor(config["path"], config["content"])
96
87
  @app.update_config(path, content)
97
88
  say "File '#{config["path"]}' updated, it will be used after next code deploy", :green
98
- rescue Client::APIError => e
99
- if e.resource_not_found == :cloud
89
+ rescue Client::NotFoundException => e
90
+ case e.resource
91
+ when :cloud
100
92
  say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
101
- elsif e.resource_not_found == :config
93
+ when :config
102
94
  say_error "Config '#{path}' not found", :with_exit => false
103
95
  say_error "You can list available config files with `shelly config list --cloud #{@app}`"
104
- elsif e.validation?
105
- e.each_error { |error| say_error error, :with_exit => false }
106
- exit 1
107
- else
108
- say_error e.message
96
+ else raise
109
97
  end
98
+ rescue Client::ValidationException => e
99
+ e.each_error { |error| say_error error, :with_exit => false }
100
+ exit 1
110
101
  end
111
102
 
112
- method_option :cloud, :type => :string, :aliases => "-c",
113
- :desc => "Specify for which cloud to delete configuration file for"
103
+ method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
114
104
  desc "delete PATH", "Delete configuration file"
115
105
  def delete(path = nil)
116
106
  say_error "No configuration file specified" unless path
117
- multiple_clouds(options[:cloud], "delete #{path}", "Specify cloud using:")
107
+ multiple_clouds(options[:cloud], "delete #{path}")
118
108
  answer = yes?("Are you sure you want to delete 'path' (yes/no): ")
119
109
  if answer
120
110
  @app.delete_config(path)
@@ -122,17 +112,14 @@ module Shelly
122
112
  else
123
113
  say "File not deleted"
124
114
  end
125
- rescue Client::APIError => e
126
- if e.resource_not_found == :cloud
115
+ rescue Client::NotFoundException => e
116
+ case e.resource
117
+ when :cloud
127
118
  say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
128
- elsif e.resource_not_found == :config
119
+ when :config
129
120
  say_error "Config '#{path}' not found", :with_exit => false
130
121
  say_error "You can list available config files with `shelly config list --cloud #{@app}`"
131
- elsif e.validation?
132
- e.each_error { |error| say_error error, :with_exit => false }
133
- exit 1
134
- else
135
- say_error e.message
122
+ else raise
136
123
  end
137
124
  end
138
125
 
@@ -166,4 +153,4 @@ module Shelly
166
153
 
167
154
  end
168
155
  end
169
- end
156
+ end
@@ -11,10 +11,9 @@ module Shelly
11
11
  before_hook :cloudfile_present?, :only => [:list, :show]
12
12
 
13
13
  desc "list", "Lists deploy logs"
14
- method_option :cloud, :type => :string, :aliases => "-c",
15
- :desc => "Specify which cloud to show deploy logs for"
14
+ method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
16
15
  def list
17
- multiple_clouds(options[:cloud], "deploys list", "Select cloud to view deploy logs using:")
16
+ multiple_clouds(options[:cloud], "deploys list")
18
17
  logs = @app.deploy_logs
19
18
  unless logs.empty?
20
19
  say "Available deploy logs", :green
@@ -24,20 +23,16 @@ module Shelly
24
23
  else
25
24
  say "No deploy logs available"
26
25
  end
27
- rescue Client::APIError => e
28
- if e.not_found?
29
- say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
30
- else
31
- raise e
32
- end
26
+ rescue Client::NotFoundException => e
27
+ raise unless e.resource == :cloud
28
+ say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
33
29
  end
34
30
 
35
31
  desc "show LOG", "Show specific deploy log"
36
- method_option :cloud, :type => :string, :aliases => "-c",
37
- :desc => "Specify which cloud to show deploy logs for"
32
+ method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
38
33
  def show(log = nil)
39
34
  specify_log(log)
40
- multiple_clouds(options[:cloud], "deploys show #{log}", "Select log and cloud to view deploy logs using:")
35
+ multiple_clouds(options[:cloud], "deploys show #{log}")
41
36
  content = @app.deploy_log(log)
42
37
  say "Log for deploy done on #{content["created_at"]}", :green
43
38
  if content["bundle_install"]
@@ -55,16 +50,13 @@ module Shelly
55
50
  if content["thin_restart"]
56
51
  say("Starting thin", :green); say(content["thin_restart"])
57
52
  end
58
- rescue Client::APIError => e
59
- if e.not_found?
60
- case e.resource_not_found
61
- when :cloud
62
- say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
63
- when :log
64
- say_error "Log not found, list all deploy logs using `shelly deploys list --cloud=#{@app.code_name}`"
65
- end
66
- else
67
- raise e
53
+ rescue Client::NotFoundException => e
54
+ case e.resource
55
+ when :cloud
56
+ say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
57
+ when :log
58
+ say_error "Log not found, list all deploy logs using `shelly deploys list --cloud=#{@app.code_name}`"
59
+ else raise
68
60
  end
69
61
  end
70
62