nucleon 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/nucleon +1 -53
- data/lib/core/core.rb +21 -3
- data/lib/core/facade.rb +146 -53
- data/lib/core/gems.rb +16 -13
- data/lib/core/manager.rb +67 -51
- data/lib/core/mixin/action/commit.rb +19 -25
- data/lib/core/mixin/action/project.rb +28 -16
- data/lib/core/mixin/action/push.rb +11 -21
- data/lib/core/plugin/action.rb +26 -14
- data/lib/core/plugin/base.rb +6 -4
- data/lib/core/util/cli.rb +20 -8
- data/lib/core/util/data.rb +0 -8
- data/lib/nucleon.rb +3 -161
- data/lib/nucleon/action/add.rb +28 -34
- data/lib/nucleon/action/create.rb +23 -28
- data/lib/nucleon/action/extract.rb +3 -3
- data/lib/nucleon/action/remove.rb +30 -26
- data/lib/nucleon/action/save.rb +26 -26
- data/lib/nucleon/action/update.rb +13 -18
- data/lib/nucleon/project/git.rb +2 -2
- data/lib/nucleon_base.rb +184 -0
- data/locales/en.yml +47 -41
- data/nucleon.gemspec +3 -2
- metadata +31 -30
data/Gemfile.lock
CHANGED
@@ -11,7 +11,7 @@ GEM
|
|
11
11
|
faraday (0.9.0)
|
12
12
|
multipart-post (>= 1.2, < 3)
|
13
13
|
git (1.2.6)
|
14
|
-
github_api (0.11.
|
14
|
+
github_api (0.11.3)
|
15
15
|
addressable (~> 2.3)
|
16
16
|
descendants_tracker (~> 0.0.1)
|
17
17
|
faraday (~> 0.8, < 0.10)
|
@@ -68,7 +68,7 @@ GEM
|
|
68
68
|
rspec-core (2.14.7)
|
69
69
|
rspec-expectations (2.14.5)
|
70
70
|
diff-lcs (>= 1.1.3, < 2.0)
|
71
|
-
rspec-mocks (2.14.
|
71
|
+
rspec-mocks (2.14.6)
|
72
72
|
sawyer (0.5.3)
|
73
73
|
addressable (~> 2.3.5)
|
74
74
|
faraday (~> 0.8, < 0.10)
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/bin/nucleon
CHANGED
@@ -1,55 +1,3 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
Signal.trap("INT") { exit 1 }
|
4
|
-
|
5
|
-
#---
|
6
|
-
|
7
2
|
require 'nucleon'
|
8
|
-
|
9
|
-
logger = Nucleon.logger
|
10
|
-
logger.info("`nucleon` invoked: #{ARGV.inspect}")
|
11
|
-
|
12
|
-
#---
|
13
|
-
|
14
|
-
$stdout.sync = true
|
15
|
-
$stderr.sync = true
|
16
|
-
|
17
|
-
#---
|
18
|
-
|
19
|
-
begin
|
20
|
-
logger.debug("Beginning execution run")
|
21
|
-
|
22
|
-
arg_components = Nucleon::Util::CLI::Parser.split(ARGV, 'nucleon <action> [ <arg> ... ]')
|
23
|
-
main_command = arg_components.shift
|
24
|
-
sub_command = arg_components.shift
|
25
|
-
sub_args = arg_components
|
26
|
-
|
27
|
-
if main_command.processed && sub_command
|
28
|
-
exit_status = Nucleon.action_cli(sub_command, sub_args)
|
29
|
-
else
|
30
|
-
puts I18n.t('nucleon.core.exec.help.usage') + ': ' + main_command.help + "\n"
|
31
|
-
puts I18n.t('nucleon.core.exec.help.header') + ":\n\n"
|
32
|
-
|
33
|
-
Nucleon.loaded_plugins(:action).each do |provider, action|
|
34
|
-
puts sprintf(" %-10s : %s\n",
|
35
|
-
"<#{provider}>",
|
36
|
-
Nucleon.action(provider, { :settings => {}, :quiet => true }).help
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
puts "\n" + I18n.t('nucleon.core.exec.help.footer') + "\n\n"
|
41
|
-
exit_status = Nucleon.code.help_wanted
|
42
|
-
end
|
43
|
-
|
44
|
-
rescue Exception => error
|
45
|
-
logger.error("Nucleon executable experienced an error:")
|
46
|
-
logger.error(error.inspect)
|
47
|
-
logger.error(error.message)
|
48
|
-
logger.error(Nucleon::Util::Data.to_yaml(error.backtrace))
|
49
|
-
|
50
|
-
Nucleon.ui.error(error.message, { :prefix => false }) if error.message
|
51
|
-
|
52
|
-
exit_status = error.status_code if error.respond_to?(:status_code)
|
53
|
-
end
|
54
|
-
|
55
|
-
exit(exit_status)
|
3
|
+
exit(Nucleon.executable(ARGV, :nucleon))
|
data/lib/core/core.rb
CHANGED
@@ -16,8 +16,8 @@ class Core < Config
|
|
16
16
|
|
17
17
|
class_label = self.class.to_s.downcase.gsub(/^nucleon::/, '')
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
self.logger = delete(:logger, class_label)
|
20
|
+
self.ui = Config.new(export).defaults({ :resource => class_label })
|
21
21
|
|
22
22
|
logger.debug('Initialized instance logger and interface')
|
23
23
|
end
|
@@ -25,7 +25,7 @@ class Core < Config
|
|
25
25
|
#-----------------------------------------------------------------------------
|
26
26
|
# Accessor / Modifiers
|
27
27
|
|
28
|
-
|
28
|
+
attr_reader :logger, :ui
|
29
29
|
|
30
30
|
#---
|
31
31
|
|
@@ -33,12 +33,30 @@ class Core < Config
|
|
33
33
|
return @@logger
|
34
34
|
end
|
35
35
|
|
36
|
+
def logger=logger
|
37
|
+
Util::Logger.loggers.delete(self.logger.resource) if self.logger
|
38
|
+
|
39
|
+
if logger.is_a?(Util::Logger)
|
40
|
+
@logger = logger
|
41
|
+
else
|
42
|
+
@logger = Util::Logger.new(logger)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
36
46
|
#---
|
37
47
|
|
38
48
|
def self.ui
|
39
49
|
return @@ui
|
40
50
|
end
|
41
51
|
|
52
|
+
def ui=ui
|
53
|
+
if ui.is_a?(Util::Console)
|
54
|
+
@ui = ui
|
55
|
+
else
|
56
|
+
@ui = Util::Console.new(ui)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
42
60
|
#-----------------------------------------------------------------------------
|
43
61
|
# General utilities
|
44
62
|
|
data/lib/core/facade.rb
CHANGED
@@ -1,35 +1,32 @@
|
|
1
1
|
|
2
2
|
module Nucleon
|
3
|
+
module Facade
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
#-----------------------------------------------------------------------------
|
7
|
-
|
8
|
-
def self.ui
|
5
|
+
def ui
|
9
6
|
Core.ui
|
10
7
|
end
|
11
8
|
|
12
|
-
def
|
9
|
+
def quiet=quiet
|
13
10
|
Util::Console.quiet = quiet
|
14
11
|
end
|
15
12
|
|
16
13
|
#---
|
17
14
|
|
18
|
-
def
|
15
|
+
def logger
|
19
16
|
Core.logger
|
20
17
|
end
|
21
18
|
|
22
|
-
def
|
19
|
+
def log_level
|
23
20
|
Util::Logger.level
|
24
21
|
end
|
25
22
|
|
26
|
-
def
|
23
|
+
def log_level=log_level
|
27
24
|
Util::Logger.level = log_level
|
28
25
|
end
|
29
26
|
|
30
27
|
#-----------------------------------------------------------------------------
|
31
28
|
|
32
|
-
def
|
29
|
+
def admin?
|
33
30
|
is_admin = ( ENV['USER'] == 'root' )
|
34
31
|
ext_admin = exec(:check_admin) do |op, results|
|
35
32
|
if op == :reduce
|
@@ -46,191 +43,219 @@ module Nucleon
|
|
46
43
|
|
47
44
|
@@codes = Codes.new
|
48
45
|
|
49
|
-
def
|
46
|
+
def code
|
50
47
|
@@codes
|
51
48
|
end
|
52
49
|
|
53
|
-
def
|
50
|
+
def codes(*codes)
|
54
51
|
Codes.codes(*codes)
|
55
52
|
end
|
56
|
-
|
53
|
+
|
57
54
|
#-----------------------------------------------------------------------------
|
58
55
|
# Core plugin interface
|
59
56
|
|
60
|
-
def
|
61
|
-
Manager.connection.reload
|
57
|
+
def reload(core = false, &code)
|
58
|
+
Manager.connection.reload(core, &code)
|
62
59
|
end
|
63
60
|
|
64
61
|
#---
|
65
62
|
|
66
|
-
def
|
63
|
+
def namespaces
|
64
|
+
Manager.connection.namespaces
|
65
|
+
end
|
66
|
+
|
67
|
+
def define_namespace(*namespaces)
|
68
|
+
Manager.connection.namespace(*namespaces)
|
69
|
+
end
|
70
|
+
|
71
|
+
#---
|
72
|
+
|
73
|
+
def types
|
67
74
|
Manager.connection.types
|
68
75
|
end
|
69
76
|
|
70
|
-
def
|
77
|
+
def define_type(type_info)
|
71
78
|
Manager.connection.define_type(type_info)
|
72
79
|
end
|
73
80
|
|
74
|
-
def
|
81
|
+
def type_default(type)
|
75
82
|
Manager.connection.type_default(type)
|
76
83
|
end
|
77
84
|
|
78
85
|
#---
|
79
86
|
|
80
|
-
def
|
87
|
+
def register(base_path, &code)
|
81
88
|
Manager.connection.register(base_path, &code)
|
82
89
|
Manager.connection.autoload
|
83
90
|
end
|
84
91
|
|
85
|
-
def
|
92
|
+
def loaded_plugins(type = nil, provider = nil)
|
86
93
|
Manager.connection.loaded_plugins(type, provider)
|
87
94
|
end
|
88
95
|
|
89
96
|
#---
|
90
97
|
|
91
|
-
def
|
98
|
+
def active_plugins(type = nil, provider = nil)
|
92
99
|
Manager.connection.plugins(type, provider)
|
93
100
|
end
|
94
101
|
|
95
102
|
#---
|
96
103
|
|
97
|
-
def
|
104
|
+
def plugin(type, provider, options = {})
|
98
105
|
Manager.connection.load(type, provider, options)
|
99
106
|
end
|
100
107
|
|
101
108
|
#---
|
102
109
|
|
103
|
-
def
|
110
|
+
def plugins(type, data, build_hash = false, keep_array = false)
|
104
111
|
Manager.connection.load_multiple(type, data, build_hash, keep_array)
|
105
112
|
end
|
106
113
|
|
107
114
|
#---
|
108
115
|
|
109
|
-
def
|
116
|
+
def create_plugin(type, provider, options = {})
|
117
|
+
Manager.connection.create(type, provider, options)
|
118
|
+
end
|
119
|
+
|
120
|
+
#---
|
121
|
+
|
122
|
+
def get_plugin(type, name)
|
110
123
|
Manager.connection.get(type, name)
|
111
124
|
end
|
112
125
|
|
113
126
|
#---
|
114
127
|
|
115
|
-
def
|
128
|
+
def remove_plugin(plugin)
|
116
129
|
Manager.connection.remove(plugin)
|
117
130
|
end
|
131
|
+
|
132
|
+
#---
|
133
|
+
|
134
|
+
def plugin_class(type)
|
135
|
+
Manager.connection.plugin_class(type)
|
136
|
+
end
|
137
|
+
|
138
|
+
#---
|
139
|
+
|
140
|
+
def provider_class(namespace, type, provider)
|
141
|
+
Manager.connection.provider_class(namespace, type, provider)
|
142
|
+
end
|
118
143
|
|
119
144
|
#-----------------------------------------------------------------------------
|
120
145
|
# Core plugin type facade
|
121
146
|
|
122
|
-
def
|
147
|
+
def extension(provider)
|
123
148
|
plugin(:extension, provider, {})
|
124
149
|
end
|
125
150
|
|
126
151
|
#---
|
127
152
|
|
128
|
-
def
|
153
|
+
def action(provider, options)
|
129
154
|
plugin(:action, provider, options)
|
130
155
|
end
|
131
156
|
|
132
|
-
def
|
157
|
+
def actions(data, build_hash = false, keep_array = false)
|
133
158
|
plugins(:action, data, build_hash, keep_array)
|
134
159
|
end
|
135
160
|
|
136
|
-
def
|
161
|
+
def action_config(provider)
|
137
162
|
action(provider, { :settings => {}, :quiet => true }).configure
|
138
163
|
end
|
139
164
|
|
140
|
-
def
|
165
|
+
def action_run(provider, options = {}, quiet = true)
|
141
166
|
Plugin::Action.exec(provider, options, quiet)
|
142
167
|
end
|
143
168
|
|
144
|
-
def
|
145
|
-
Plugin::Action.exec_cli(provider, args, quiet)
|
169
|
+
def action_cli(provider, args = [], quiet = false, name = :nucleon)
|
170
|
+
Plugin::Action.exec_cli(provider, args, quiet, name)
|
146
171
|
end
|
147
172
|
|
148
173
|
#---
|
149
174
|
|
150
|
-
def
|
175
|
+
def project(options, provider = nil)
|
151
176
|
plugin(:project, provider, options)
|
152
177
|
end
|
153
178
|
|
154
|
-
def
|
179
|
+
def projects(data, build_hash = false, keep_array = false)
|
155
180
|
plugins(:project, data, build_hash, keep_array)
|
156
181
|
end
|
157
182
|
|
158
183
|
#-----------------------------------------------------------------------------
|
159
184
|
# Utility plugin type facade
|
160
185
|
|
161
|
-
def
|
186
|
+
def command(options, provider = nil)
|
162
187
|
plugin(:command, provider, options)
|
163
188
|
end
|
164
189
|
|
165
|
-
def
|
190
|
+
def commands(data, build_hash = false, keep_array = false)
|
166
191
|
plugins(:command, data, build_hash, keep_array)
|
167
192
|
end
|
168
193
|
|
169
194
|
#---
|
170
195
|
|
171
|
-
def
|
196
|
+
def event(options, provider = nil)
|
172
197
|
plugin(:event, provider, options)
|
173
198
|
end
|
174
199
|
|
175
|
-
def
|
200
|
+
def events(data, build_hash = false, keep_array = false)
|
176
201
|
plugins(:event, data, build_hash, keep_array)
|
177
202
|
end
|
178
203
|
|
179
204
|
#---
|
180
205
|
|
181
|
-
def
|
206
|
+
def template(options, provider = nil)
|
182
207
|
plugin(:template, provider, options)
|
183
208
|
end
|
184
209
|
|
185
|
-
def
|
210
|
+
def templates(data, build_hash = false, keep_array = false)
|
186
211
|
plugins(:template, data, build_hash, keep_array)
|
187
212
|
end
|
188
213
|
|
189
214
|
#---
|
190
215
|
|
191
|
-
def
|
216
|
+
def translator(options, provider = nil)
|
192
217
|
plugin(:translator, provider, options)
|
193
218
|
end
|
194
219
|
|
195
|
-
def
|
220
|
+
def translators(data, build_hash = false, keep_array = false)
|
196
221
|
plugins(:translator, data, build_hash, keep_array)
|
197
222
|
end
|
198
223
|
|
199
224
|
#-----------------------------------------------------------------------------
|
200
225
|
# Plugin extensions
|
201
226
|
|
202
|
-
def
|
227
|
+
def exec(method, options = {}, &code)
|
203
228
|
Manager.connection.exec(method, options, &code)
|
204
229
|
end
|
205
230
|
|
206
231
|
#---
|
207
232
|
|
208
|
-
def
|
209
|
-
Manager.connection.config(
|
233
|
+
def config(type, options = {})
|
234
|
+
Manager.connection.config(type, options)
|
210
235
|
end
|
211
236
|
|
212
237
|
#---
|
213
238
|
|
214
|
-
def
|
239
|
+
def check(method, options = {})
|
215
240
|
Manager.connection.check(method, options)
|
216
241
|
end
|
217
242
|
|
218
243
|
#---
|
219
244
|
|
220
|
-
def
|
245
|
+
def value(method, value, options = {})
|
221
246
|
Manager.connection.value(method, value, options)
|
222
247
|
end
|
223
248
|
|
224
249
|
#---
|
225
250
|
|
226
|
-
def
|
251
|
+
def collect(method, options = {})
|
227
252
|
Manager.connection.collect(method, options)
|
228
253
|
end
|
229
254
|
|
230
255
|
#-----------------------------------------------------------------------------
|
231
256
|
# External execution
|
232
257
|
|
233
|
-
def
|
258
|
+
def run
|
234
259
|
begin
|
235
260
|
logger.debug("Running contained process at #{Time.now}")
|
236
261
|
yield
|
@@ -248,7 +273,7 @@ module Nucleon
|
|
248
273
|
|
249
274
|
#---
|
250
275
|
|
251
|
-
def
|
276
|
+
def cli_run(command, options = {}, &code)
|
252
277
|
command = command.join(' ') if command.is_a?(Array)
|
253
278
|
config = Config.ensure(options)
|
254
279
|
|
@@ -262,22 +287,90 @@ module Nucleon
|
|
262
287
|
result
|
263
288
|
end
|
264
289
|
|
290
|
+
#---
|
291
|
+
|
292
|
+
def executable(args, name = 'nucleon') #ARGV
|
293
|
+
Signal.trap("INT") { exit 1 }
|
294
|
+
|
295
|
+
logger.info("`#{name}` invoked: #{args.inspect}")
|
296
|
+
|
297
|
+
$stdout.sync = true
|
298
|
+
$stderr.sync = true
|
299
|
+
|
300
|
+
exit_status = nil
|
301
|
+
|
302
|
+
begin
|
303
|
+
logger.debug("Beginning execution run")
|
304
|
+
|
305
|
+
arg_components = Util::CLI::Parser.split(args, "#{name} <action> [ <arg> ... ]")
|
306
|
+
main_command = arg_components.shift
|
307
|
+
sub_command = arg_components.shift
|
308
|
+
sub_args = arg_components
|
309
|
+
|
310
|
+
if main_command.processed && sub_command
|
311
|
+
exit_status = action_cli(sub_command, sub_args, false, name)
|
312
|
+
else
|
313
|
+
puts I18n.t('nucleon.core.exec.help.usage') + ': ' + main_command.help + "\n"
|
314
|
+
puts I18n.t('nucleon.core.exec.help.header') + ":\n\n"
|
315
|
+
|
316
|
+
help_data = {}
|
317
|
+
extended_help = main_command.options[:extended_help]
|
318
|
+
|
319
|
+
loaded_plugins(:action).each do |provider, data|
|
320
|
+
namespace = data[:namespace]
|
321
|
+
|
322
|
+
help_data[namespace] = {} unless help_data.has_key?(namespace)
|
323
|
+
help_data[namespace][provider] = data
|
324
|
+
end
|
325
|
+
|
326
|
+
help_data.each do |namespace, actions|
|
327
|
+
actions.each do |provider, data|
|
328
|
+
if extended_help
|
329
|
+
help_text = action(provider, { :args => [ '-h' ], :quiet => true }).help
|
330
|
+
else
|
331
|
+
help_text = action(provider, { :settings => {}, :quiet => true }).help
|
332
|
+
end
|
333
|
+
puts sprintf(" %-15s : %s\n", namespace, help_text)
|
334
|
+
end
|
335
|
+
puts "\n"
|
336
|
+
end
|
337
|
+
|
338
|
+
puts "\n" + I18n.t('nucleon.core.exec.help.footer') + "\n\n"
|
339
|
+
exit_status = code.help_wanted
|
340
|
+
end
|
341
|
+
|
342
|
+
rescue Exception => error
|
343
|
+
logger.error("Nucleon executable experienced an error:")
|
344
|
+
logger.error(error.inspect)
|
345
|
+
logger.error(error.message)
|
346
|
+
logger.error(Util::Data.to_yaml(error.backtrace))
|
347
|
+
|
348
|
+
ui.error(error.message, { :prefix => false }) if error.message
|
349
|
+
|
350
|
+
exit_status = error.status_code if error.respond_to?(:status_code)
|
351
|
+
exit_status = code.unknown_status if exit_status.nil?
|
352
|
+
end
|
353
|
+
exit_status
|
354
|
+
end
|
355
|
+
|
265
356
|
#-----------------------------------------------------------------------------
|
266
357
|
# Utilities
|
267
358
|
|
268
|
-
def
|
359
|
+
def class_name(name, separator = '::', want_array = false)
|
269
360
|
Manager.connection.class_name(name, separator, want_array)
|
270
361
|
end
|
271
362
|
|
272
363
|
#---
|
273
364
|
|
274
|
-
def
|
365
|
+
def class_const(name, separator = '::')
|
275
366
|
Manager.connection.class_const(name, separator)
|
276
367
|
end
|
277
368
|
|
278
369
|
#---
|
279
370
|
|
280
|
-
def
|
371
|
+
def sha1(data)
|
281
372
|
Digest::SHA1.hexdigest(Util::Data.to_json(data, false))
|
282
373
|
end
|
283
374
|
end
|
375
|
+
end
|
376
|
+
|