redipress 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1cd5a369540a7fac84e4543d82e3676e120654e
4
- data.tar.gz: 41b2088329ce194c4c07ee018a838a852d4c5836
3
+ metadata.gz: a66ae6d877c3fa7b777a481c27b4e689bca89fed
4
+ data.tar.gz: 996402566da246e8387c35452d0fdc0a04b2be20
5
5
  SHA512:
6
- metadata.gz: 1c03498f350b079fdb90fef7de9394091e4b0fcdafc56ffc52922e5929a53fa753f78dd7543ee8def7bd64fc867674abf67c5cb2aef82453ad995dcc81ee90eb
7
- data.tar.gz: c7fa1fccfb4b15c66fdeb7d2d931d8d0756470792566968ba6e76433e351ab8ba981f7c645fb241c5f3bd0af486ade6824cdf01b0166711d7212e27e355133e5
6
+ metadata.gz: dd7b12ffb774b49aa25650ca6c0971b849e3a2192019ece186215740596bdf4dc876cf049671661711dcf3a349140af9c987f5dbbc07b14b140313cc8086efc6
7
+ data.tar.gz: a400e6f7a8d9797f168fdef7634d6ed585e88167d38a52d6252d04e30cc18ba1134f3c824da614c1b7764b9600322522b65d8cb9f2128a93e43c9633c2ae28bc
@@ -20,13 +20,19 @@ module RediPress
20
20
  new_line
21
21
 
22
22
  # Get the configuration
23
- configuration = prompt_for_configuration
23
+ configurations = prompt_for_configurations
24
24
 
25
- # Print a new line
26
- new_line
25
+ # Create a Hash to hold the options
26
+ options = Hash.new
27
+
28
+ # Loop over each configuration
29
+ configurations.each do |configuration|
30
+ # Print a new line
31
+ new_line
27
32
 
28
- # Get the configuration's options
29
- options = prompt_for_configuration_options(configuration)
33
+ # Get the configuration's options
34
+ options[configuration.slug] = prompt_for_configuration_options(configuration)
35
+ end
30
36
 
31
37
  # Print a new line
32
38
  new_line
@@ -34,59 +40,96 @@ module RediPress
34
40
  # Prompt to continue
35
41
  exit(1) unless prompt.yes?("Proceed with the above settings?")
36
42
 
37
- # Print a new line
38
- new_line
39
-
40
- begin
41
- # Check if the configuration is compatible with the host
42
- compatible = configuration.compatible?(host, options)
43
- rescue => error
43
+ # Loop over each configuration
44
+ configurations.each do |configuration|
45
+ # Print a new line
44
46
  new_line
45
- prompt.error("The configuration raised an error.")
46
- prompt.error("See the error report below for more information:")
47
- prompt.error("--------------------------------------------------")
48
47
 
49
- raise error
50
- end
48
+ begin
49
+ # Check if the configuration is compatible with the host
50
+ compatible = configuration.compatible?(host, options)
51
+ rescue => e
52
+ # Print a new line
53
+ new_line
51
54
 
52
- # Check if the server is not compatible with the configuration
53
- unless compatible
54
- prompt.error("The configuration '#{configuration}' is not compatible with #{host.username}@#{host.hostname}")
55
+ # Print an error message
56
+ prompt.error("An exception was raised whilst running a configuration:")
57
+ prompt.error("-------------------------------------------------------")
55
58
 
56
- exit 1
57
- end
59
+ raise e
60
+ end
58
61
 
59
- begin
60
- # Perform the configuration on the server
61
- result = configuration.configure(host, options)
62
- rescue => error
63
- new_line
64
- prompt.error("The configuration raised an error.")
65
- prompt.error("See the error report below for more information:")
66
- prompt.error("--------------------------------------------------")
62
+ # Check if the configuration is not compatible
63
+ unless compatible
64
+ # Print a warning message
65
+ prompt.warning("'#{configuration.name}' is not compatible with #{host.username}@#{host.hostname}")
67
66
 
68
- raise error
67
+ exit 1
68
+ end
69
69
  end
70
70
 
71
- # Check if the result is nil
72
- if result.nil?
73
- # The server failed to configure
74
- prompt.error("Oh dear. It looks like something went wrong whilst configuring the server.")
71
+ # Print a message
72
+ prompt.ok("The selected configurations appear to be compatible with #{host.username}@#{host.hostname}")
73
+
74
+ # Create a Hash to hold the results
75
+ results = Hash.new
75
76
 
76
- exit 1
77
+ # Loop over each configuration
78
+ configurations.each do |configuration|
79
+ # Print a new line
80
+ new_line
81
+
82
+ # Print a message
83
+ prompt.ok("Configuring '#{configuration.name}' ...")
84
+ prompt.ok("------------------------------------------------------------")
85
+
86
+ begin
87
+ # Perform the configuration on the server
88
+ results[configuration.slug] = configuration.configure(host, options[configuration.slug])
89
+ rescue RediPress::ConfigurationFailed => e
90
+ # Print a new line
91
+ new_line
92
+
93
+ # Print an error message
94
+ prompt.error("Configuration '#{configuration.name}' failed:")
95
+ prompt.error("------------------------------------------------------------")
96
+ prompt.error(e.error)
97
+
98
+ exit 1
99
+ rescue => e
100
+ # Print a new line
101
+ new_line
102
+
103
+ # Print an error message
104
+ prompt.error("Configuration '#{configuration.name}' raised an error:")
105
+ prompt.error("------------------------------------------------------------")
106
+
107
+ raise e
108
+ end
77
109
  end
78
110
 
111
+ # Print a new line
112
+ new_line
113
+
79
114
  # The server has been configured
80
115
  prompt.ok("Woo hoo! Your server has been configured.")
81
116
 
82
- # Print a new line
83
- new_line
117
+ # Loop over each configuration
118
+ configurations.each do |configuration|
119
+ # Get the result
120
+ result = results[configuration.slug]
121
+
122
+ # Go next if there aren't any results to output
123
+ next if result.nil? || result.empty? || false == result.is_a?(Hash)
124
+
125
+ # Print a new line
126
+ new_line
84
127
 
85
- # Check if there are any results to Show
86
- unless result.empty?
87
128
  # Print a table containing the results
88
129
  puts TTY::Table.new(rows: result.map { |k, v| [" #{k} ", " #{v} "] }).render(:ascii)
89
130
  end
131
+
132
+ nil
90
133
  end
91
134
 
92
135
  # Set the default task to execute
@@ -132,25 +175,24 @@ module RediPress
132
175
  host
133
176
  end
134
177
 
135
- # Prompt the user for the configuration to use.
178
+ # Prompt the user for the configurations to use
136
179
  #
137
180
  # Example:
138
- # >> prompt_for_configuration
139
- # => [#<Test:0x00000000000000>, { "username" => "test" }]
181
+ # >> prompt_for_configurations
182
+ # => [#<RediPress::Configuration::Test:0x00000000000000>]
140
183
  #
141
- def prompt_for_configuration
184
+ def prompt_for_configurations
142
185
  # Print a short message to explain why we need the following information
143
- prompt.ok("Pick the configuration you'd like to use:")
186
+ prompt.ok("Pick the configurations you'd like to use:")
144
187
 
145
188
  begin
146
189
  # Load the actual configuration classes
147
190
  configurations = RediPress::Configuration.all
148
- rescue error
191
+ rescue e
149
192
  prompt.error("Unable to load one or more configurations.")
150
- prompt.error("See the error report below for more information:")
151
193
  prompt.error("--------------------------------------------------")
152
194
 
153
- raise error
195
+ raise e
154
196
  end
155
197
 
156
198
  # Ensure there is at least one configuration available
@@ -161,13 +203,13 @@ module RediPress
161
203
  raise RediPress::NoConfigurationsAvailable
162
204
  end
163
205
 
164
- # Prompt for the configuration to use
165
- configuration = prompt.select("Configuration:", configurations.values)
206
+ # Prompt for the configurations to use
207
+ configurations = prompt.multi_select("Configurations:", configurations.values)
166
208
 
167
- configuration
209
+ configurations
168
210
  end
169
211
 
170
- # Prompt the user for all options required by the specified configuration.
212
+ # Prompt the user for all options required by the specified configuration
171
213
  #
172
214
  # Example:
173
215
  # >> prompt_for_configuration_options(configuration)
@@ -177,7 +219,7 @@ module RediPress
177
219
  return nil unless configuration.parameters && configuration.parameters.count > 0
178
220
 
179
221
  # Print a short message to explain why we need the following information
180
- prompt.ok("These options are required by the configuration you chose:")
222
+ prompt.ok("Options for #{configuration.name}:")
181
223
 
182
224
  # Create an empty hash to store the configuration's options
183
225
  options = Hash.new
@@ -185,19 +227,22 @@ module RediPress
185
227
  # Loop through each parameter on the configuration
186
228
  configuration.parameters.each do |parameter|
187
229
  if :text == parameter.type
188
- options[parameter.slug] = prompt.ask("#{parameter.name}:") do |q|
230
+ options[parameter.slug] = prompt.ask(" #{parameter.name}:") do |q|
189
231
  q.required(true)
190
232
  q.validate(parameter.validation) if parameter.validation
191
233
  q.default(parameter.default) if parameter.default
192
234
  end
193
- elsif :yesno == parameter.type
194
- options[parameter.slug] = prompt.yes?("#{parameter.name}:")
235
+ elsif :yes == parameter.type
236
+ options[parameter.slug] = prompt.yes?(" #{parameter.name}:")
237
+ elsif :no == parameter.type
238
+ options[parameter.slug] = prompt.no?(" #{parameter.name}:")
195
239
  elsif :select == parameter.type
196
- options[parameter.slug] = prompt.select("#{parameter.name}:", parameter.options)
240
+ options[parameter.slug] = prompt.select(" #{parameter.name}:", parameter.options)
197
241
  elsif :multi_select == parameter.type
198
- options[parameter.slug] = prompt.multi_select("#{parameter.name}:", parameter.options)
242
+ options[parameter.slug] = prompt.multi_select(" #{parameter.name}:", parameter.options)
199
243
  else
200
- prompt.error("The configuration requested an unknown parameter type.")
244
+ prompt.error("'#{parameter.name}' has an unknown type of '#{parameter.type}'.")
245
+
201
246
  exit 1
202
247
  end
203
248
  end
@@ -52,6 +52,16 @@ module RediPress
52
52
  end
53
53
  end
54
54
 
55
+ # Get the slug of the configuration
56
+ #
57
+ # Example:
58
+ # >> configuration.slug
59
+ # => "test"
60
+ #
61
+ def slug
62
+ RediPress::Configuration.slug_for(self.class)
63
+ end
64
+
55
65
  # Get the name of the configuration
56
66
  #
57
67
  # Example:
@@ -99,8 +109,7 @@ module RediPress
99
109
  end
100
110
 
101
111
  # Configure the server
102
- # This method should return a hash (either empty or with info to display) on
103
- # success and nil if an error occurs.
112
+ # This method should return a hash with info to display (if needed) or nil
104
113
  #
105
114
  # Arguments:
106
115
  # host: (SSHKit::Host)
@@ -113,6 +122,22 @@ module RediPress
113
122
  def configure(host, options)
114
123
  raise RediPress::SetupNotImplemented
115
124
  end
125
+
126
+ # Fail with an error
127
+ #
128
+ # Arguments:
129
+ # error: (String)
130
+ #
131
+ # Example:
132
+ # >> configuration.fail("Test error")
133
+ # => nil
134
+ #
135
+ # Raises:
136
+ # RediPress::ConfigurationFailed: When this function is called
137
+ #
138
+ def fail(error)
139
+ raise RediPress::ConfigurationFailed.new(self, error)
140
+ end
116
141
  end
117
142
  end
118
143
  end
@@ -68,6 +68,24 @@ module RediPress
68
68
  "RediPress::Configuration::#{klass}"
69
69
  end
70
70
 
71
+ # Get the slug for a configuration class.
72
+ #
73
+ # Arguments:
74
+ # klass: (Class)
75
+ #
76
+ # Example:
77
+ # >> RediPress::Configuration.slug_for RediPress::Configuration::Test
78
+ # => "test"
79
+ #
80
+ def self.slug_for(klass)
81
+ slug = klass.to_s.split("::").last
82
+ slug.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
83
+ slug.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
84
+ slug.tr!("-", "_")
85
+ slug.downcase!
86
+ slug
87
+ end
88
+
71
89
  # Load a configuration from the configurations directory.
72
90
  #
73
91
  # Arguments:
@@ -32,4 +32,19 @@ module RediPress
32
32
  "The setup function has not been implemented by the configuration."
33
33
  end
34
34
  end
35
+
36
+ # A RuntimeError subclass for when a configuration fails.
37
+ #
38
+ class ConfigurationFailed < RuntimeError
39
+ attr_reader :configuration, :error
40
+
41
+ def initialize(configuration, error)
42
+ @configuration = configuration
43
+ @error = error
44
+ end
45
+
46
+ def to_s
47
+ "The configuration '#{@configuration.name}' failed: #{@error}"
48
+ end
49
+ end
35
50
  end
@@ -1,9 +1,5 @@
1
1
  module RediPress
2
2
  # The current version of the gem.
3
3
  #
4
- VERSION = '0.0.2'
5
-
6
- # The directory where all configurations are stored.
7
- #
8
- CONFIGURATIONS_DIR = File.join(File.dirname(__FILE__), "configurations")
4
+ VERSION = '0.0.3'
9
5
  end
data/redipress.gemspec CHANGED
@@ -16,10 +16,10 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.executables << 'redipress'
18
18
 
19
- s.add_runtime_dependency "thor", "~> 0.19", "0.19.1"
20
- s.add_runtime_dependency "tty-prompt", "~> 0.3", "0.3.0"
21
- s.add_runtime_dependency "tty-table", "~> 0.4", "0.4.0"
22
- s.add_runtime_dependency "tty-spinner", "~> 0.1", "0.1.0"
23
- s.add_runtime_dependency "sshkey", "~> 1.8", "1.8.0"
24
- s.add_runtime_dependency "sshkit", "~> 1.8", "1.8.1"
19
+ s.add_runtime_dependency "thor", "~> 0.19", ">= 0.19.1"
20
+ s.add_runtime_dependency "tty-prompt", "~> 0.3", ">= 0.3.0"
21
+ s.add_runtime_dependency "tty-table", "~> 0.4", ">= 0.4.0"
22
+ s.add_runtime_dependency "tty-spinner", "~> 0.1", ">= 0.1.0"
23
+ s.add_runtime_dependency "sshkey", "~> 1.8", ">= 1.8.0"
24
+ s.add_runtime_dependency "sshkit", "~> 1.8", ">= 1.8.1"
25
25
  end
metadata CHANGED
@@ -1,133 +1,133 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redipress
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rediweb Hosting
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-05 00:00:00.000000000 Z
11
+ date: 2016-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.19'
20
- - - '='
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: 0.19.1
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ~>
27
+ - - "~>"
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0.19'
30
- - - '='
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.19.1
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: tty-prompt
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ~>
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0.3'
40
- - - '='
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: 0.3.0
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ~>
47
+ - - "~>"
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0.3'
50
- - - '='
50
+ - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: 0.3.0
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: tty-table
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - ~>
57
+ - - "~>"
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0.4'
60
- - - '='
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: 0.4.0
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ~>
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0.4'
70
- - - '='
70
+ - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: 0.4.0
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: tty-spinner
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - ~>
77
+ - - "~>"
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0.1'
80
- - - '='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.1.0
83
83
  type: :runtime
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0.1'
90
- - - '='
90
+ - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: 0.1.0
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: sshkey
95
95
  requirement: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - ~>
97
+ - - "~>"
98
98
  - !ruby/object:Gem::Version
99
99
  version: '1.8'
100
- - - '='
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: 1.8.0
103
103
  type: :runtime
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - ~>
107
+ - - "~>"
108
108
  - !ruby/object:Gem::Version
109
109
  version: '1.8'
110
- - - '='
110
+ - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: 1.8.0
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: sshkit
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - ~>
117
+ - - "~>"
118
118
  - !ruby/object:Gem::Version
119
119
  version: '1.8'
120
- - - '='
120
+ - - ">="
121
121
  - !ruby/object:Gem::Version
122
122
  version: 1.8.1
123
123
  type: :runtime
124
124
  prerelease: false
125
125
  version_requirements: !ruby/object:Gem::Requirement
126
126
  requirements:
127
- - - ~>
127
+ - - "~>"
128
128
  - !ruby/object:Gem::Version
129
129
  version: '1.8'
130
- - - '='
130
+ - - ">="
131
131
  - !ruby/object:Gem::Version
132
132
  version: 1.8.1
133
133
  description: Automated server configuration!
@@ -137,7 +137,7 @@ executables:
137
137
  extensions: []
138
138
  extra_rdoc_files: []
139
139
  files:
140
- - .gitignore
140
+ - ".gitignore"
141
141
  - LICENSE
142
142
  - bin/redipress
143
143
  - lib/redipress.rb
@@ -161,12 +161,12 @@ require_paths:
161
161
  - lib
162
162
  required_ruby_version: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - '>='
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  requirements:
169
- - - '>='
169
+ - - ">="
170
170
  - !ruby/object:Gem::Version
171
171
  version: '0'
172
172
  requirements: []