legionio 0.3.2 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +27 -10
- data/.gitignore +1 -0
- data/.rubocop.yml +7 -2
- data/CHANGELOG.md +21 -0
- data/Dockerfile +9 -0
- data/README.md +157 -45
- data/Rakefile +0 -6
- data/bitbucket-pipelines.yml +16 -52
- data/docker_deploy.rb +10 -0
- data/exe/legion +3 -51
- data/exe/legionio +53 -0
- data/exe/lex_gen +5 -0
- data/{legion.gemspec → legionio.gemspec} +25 -20
- data/lib/legion.rb +4 -0
- data/lib/legion/cli.rb +56 -0
- data/lib/legion/cli/chain.rb +35 -0
- data/lib/legion/cli/cohort.rb +10 -0
- data/lib/legion/cli/function.rb +41 -0
- data/lib/legion/cli/lex/actor.rb +31 -0
- data/lib/legion/cli/lex/exchange.rb +32 -0
- data/lib/legion/cli/lex/message.rb +32 -0
- data/lib/legion/cli/lex/queue.rb +45 -0
- data/lib/legion/cli/lex/runner.rb +70 -0
- data/lib/legion/cli/lex/templates/actor.erb +6 -0
- data/{docs/_build/html/_sources/overview.rst.txt → lib/legion/cli/lex/templates/actor_spec.erb} +0 -0
- data/lib/legion/cli/lex/templates/base/bitbucket.yml.erb +69 -0
- data/lib/legion/cli/lex/templates/base/gemfile.erb +3 -0
- data/lib/legion/cli/lex/templates/base/gemspec.erb +26 -0
- data/lib/legion/cli/lex/templates/base/gitignore.erb +11 -0
- data/lib/legion/cli/lex/templates/base/lex.erb +9 -0
- data/lib/legion/cli/lex/templates/base/lex_spec.erb +5 -0
- data/lib/legion/cli/lex/templates/base/lic.erb +21 -0
- data/lib/legion/cli/lex/templates/base/rakefile.erb +6 -0
- data/lib/legion/cli/lex/templates/base/readme.md.erb +2 -0
- data/lib/legion/cli/lex/templates/base/rubocop.yml.erb +15 -0
- data/lib/legion/cli/lex/templates/base/spec_helper.rb.erb +11 -0
- data/lib/legion/cli/lex/templates/base/version.erb +7 -0
- data/lib/legion/cli/lex/templates/exchange.erb +11 -0
- data/lib/legion/cli/lex/templates/exchange_spec.erb +0 -0
- data/lib/legion/cli/lex/templates/message.erb +23 -0
- data/lib/legion/cli/lex/templates/message_spec.erb +0 -0
- data/lib/legion/cli/lex/templates/queue.erb +12 -0
- data/lib/legion/cli/lex/templates/queue_helper.erb +24 -0
- data/lib/legion/cli/lex/templates/queue_spec.erb +11 -0
- data/lib/legion/cli/lex/templates/runner.erb +11 -0
- data/lib/legion/cli/lex/templates/runner_spec.erb +11 -0
- data/lib/legion/cli/relationship.rb +22 -0
- data/lib/legion/cli/task.rb +49 -0
- data/lib/legion/cli/trigger.rb +88 -0
- data/lib/legion/cli/version.rb +5 -0
- data/lib/legion/extensions.rb +35 -1
- data/lib/legion/extensions/actors/base.rb +0 -2
- data/lib/legion/extensions/actors/poll.rb +0 -1
- data/lib/legion/extensions/actors/subscription.rb +1 -0
- data/lib/legion/extensions/core.rb +9 -4
- data/lib/legion/extensions/helpers/base.rb +3 -3
- data/lib/legion/extensions/helpers/logger.rb +3 -6
- data/lib/legion/extensions/helpers/task.rb +1 -1
- data/lib/legion/lex.rb +89 -0
- data/lib/legion/service.rb +34 -3
- data/lib/legion/version.rb +1 -1
- metadata +196 -82
- data/bin/console +0 -16
- data/bin/legion +0 -49
- data/bin/setup +0 -8
- data/bin/test +0 -32
- data/docs/Makefile +0 -20
- data/docs/_build/doctrees/environment.pickle +0 -0
- data/docs/_build/doctrees/index.doctree +0 -0
- data/docs/_build/doctrees/overview.doctree +0 -0
- data/docs/_build/html/.buildinfo +0 -4
- data/docs/_build/html/_sources/index.rst.txt +0 -28
- data/docs/_build/html/_static/alabaster.css +0 -701
- data/docs/_build/html/_static/basic.css +0 -855
- data/docs/_build/html/_static/custom.css +0 -1
- data/docs/_build/html/_static/doctools.js +0 -315
- data/docs/_build/html/_static/documentation_options.js +0 -12
- data/docs/_build/html/_static/file.png +0 -0
- data/docs/_build/html/_static/jquery-3.5.1.js +0 -10872
- data/docs/_build/html/_static/jquery.js +0 -2
- data/docs/_build/html/_static/language_data.js +0 -297
- data/docs/_build/html/_static/minus.png +0 -0
- data/docs/_build/html/_static/plus.png +0 -0
- data/docs/_build/html/_static/pygments.css +0 -82
- data/docs/_build/html/_static/searchtools.js +0 -514
- data/docs/_build/html/_static/underscore-1.3.1.js +0 -999
- data/docs/_build/html/_static/underscore.js +0 -31
- data/docs/_build/html/genindex.html +0 -101
- data/docs/_build/html/index.html +0 -117
- data/docs/_build/html/objects.inv +0 -6
- data/docs/_build/html/overview.html +0 -98
- data/docs/_build/html/search.html +0 -110
- data/docs/_build/html/searchindex.js +0 -1
- data/docs/conf.py +0 -54
- data/docs/index.rst +0 -28
- data/docs/make.bat +0 -35
- data/lib/legion/exceptions/handled_task.rb +0 -6
- data/lib/legion/exceptions/invalidjson.rb +0 -5
- data/lib/legion/exceptions/missingargument.rb +0 -6
- data/lib/legion/exceptions/wrongtype.rb +0 -10
- data/lib/legion/exceptions/wrongtypes/array.rb +0 -8
- data/lib/legion/exceptions/wrongtypes/hash.rb +0 -8
- data/lib/legion/exceptions/wrongtypes/integer.rb +0 -8
- data/lib/legion/exceptions/wrongtypes/string.rb +0 -8
@@ -0,0 +1,22 @@
|
|
1
|
+
module Legion
|
2
|
+
class Cli
|
3
|
+
class Relationship < Thor
|
4
|
+
desc 'create', 'creates a new relationship'
|
5
|
+
def create(_name, _type)
|
6
|
+
trigger_id = invoke('legion:cli:function:find', [], internal: true, capture: true) # rubocop:disable Lint/UselessAssignment
|
7
|
+
end
|
8
|
+
|
9
|
+
desc 'activate', 'actives a relationship'
|
10
|
+
def active; end
|
11
|
+
|
12
|
+
desc 'deactivate', 'deactivates a relationship'
|
13
|
+
def deactivate; end
|
14
|
+
|
15
|
+
desc 'modify', 'modify an existing relationship'
|
16
|
+
def modify; end
|
17
|
+
|
18
|
+
desc 'delete', 'deletes a relationship'
|
19
|
+
def delete; end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Legion
|
2
|
+
class Cli
|
3
|
+
class Task < Thor
|
4
|
+
package_name 'Legion'
|
5
|
+
|
6
|
+
option :limit, type: :numeric, required: true, default: 10, desc: 'how many tasks to return'
|
7
|
+
desc 'show', 'show'
|
8
|
+
option :status, type: :string, required: false, desc: 'search for specific status'
|
9
|
+
def show
|
10
|
+
Legion::Service.new(cache: false, crypt: false, extensions: false, log_level: 'error')
|
11
|
+
rows = [%w[id relationship function status]]
|
12
|
+
Legion::Data::Model::Task.limit(options[:limit]).order(:id).reverse_each do |row|
|
13
|
+
rows.push([row.values[:id], row.values[:relationship_id], row.values[:function_id], row.values[:status]])
|
14
|
+
end
|
15
|
+
|
16
|
+
print_table rows
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'test', 'test'
|
20
|
+
def status(id)
|
21
|
+
Legion::Service.new(cache: false, crypt: false, extensions: false, log_level: 'error')
|
22
|
+
say Legion::Data::Model::Task[id].values
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'logs', 'logs'
|
26
|
+
option :limit, type: :numeric, required: true, default: 10, desc: 'how many tasks to return'
|
27
|
+
def logs(id)
|
28
|
+
Legion::Service.new(cache: false, crypt: false, extensions: false, log_level: 'error')
|
29
|
+
rows = [%w[id node_id created entry]]
|
30
|
+
Legion::Data::Model::TaskLog.where(task_id: id).limit(options[:limit]).each do |row|
|
31
|
+
rows.push([row.values[:id], row.values[:node_id], row.values[:created], row.values[:entry]])
|
32
|
+
end
|
33
|
+
print_table rows
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'purge', 'purge'
|
37
|
+
def purge
|
38
|
+
Legion::Service.new(cache: false, crypt: false, extensions: false, log_level: 'error')
|
39
|
+
days = ask 'how many days do you want to keep?', default: 7
|
40
|
+
dataset = Legion::Data::Model::Task.where { created < DateTime.now - days.to_i }
|
41
|
+
yes? "This will delete #{dataset.count} tasks, continue?", :red
|
42
|
+
dataset.delete
|
43
|
+
say 'Done!'
|
44
|
+
end
|
45
|
+
|
46
|
+
default_task :show
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Legion
|
2
|
+
class Cli
|
3
|
+
class Trigger < Thor
|
4
|
+
desc 'queue', 'used to send a job directly to a worker via Legion::Transport'
|
5
|
+
option :extension, type: :string, required: false, desc: 'extension short name'
|
6
|
+
option :runner, type: :string, required: false, desc: 'runner short name'
|
7
|
+
option :function, type: :string, required: false, desc: 'function short name'
|
8
|
+
option :delay, type: :numeric, default: 0, desc: 'how long to wait before running the task'
|
9
|
+
def queue(*args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
|
10
|
+
Legion::Service.new(cache: false, crypt: false, extensions: false, log_level: 'error')
|
11
|
+
include Legion::Extensions::Helpers::Task
|
12
|
+
response = if options['extension'].is_a? String
|
13
|
+
options[:extension]
|
14
|
+
else
|
15
|
+
ask 'trigger extension?', limited_to: Legion::Data::Model::Extension.map(:name)
|
16
|
+
end
|
17
|
+
trigger_extension = Legion::Data::Model::Extension.where(name: response).first
|
18
|
+
runners = Legion::Data::Model::Runner.where(extension_id: trigger_extension.values[:id])
|
19
|
+
if runners.count == 1
|
20
|
+
trigger_runner = runners.first
|
21
|
+
say "Auto selecting #{trigger_runner.values[:name]} since it is the only option for runners"
|
22
|
+
else
|
23
|
+
response = options[:runner].is_a?(String) ? options[:runner] : ask('trigger runner?', limited_to: runners.map(:name))
|
24
|
+
trigger_runner = Legion::Data::Model::Runner.where(name: response).where(extension_id: trigger_extension.values[:id]).first
|
25
|
+
end
|
26
|
+
|
27
|
+
functions = Legion::Data::Model::Function.where(runner_id: trigger_runner.values[:id])
|
28
|
+
|
29
|
+
if functions.count == 1
|
30
|
+
trigger_function = functions.first
|
31
|
+
say "Auto selecting #{trigger_function.values[:name]} since it is the only option for functions"
|
32
|
+
else
|
33
|
+
response = if options[:function].is_a?(String)
|
34
|
+
options[:function]
|
35
|
+
else
|
36
|
+
ask('trigger function?',
|
37
|
+
limited_to: Legion::Data::Model::Function.where(runner_id: trigger_runner.values[:id]).map(:name))
|
38
|
+
end
|
39
|
+
trigger_function = Legion::Data::Model::Function.where(runner_id: trigger_runner.values[:id]).where(name: response).first
|
40
|
+
end
|
41
|
+
say "#{trigger_runner.values[:namespace]}.#{trigger_function.values[:name]} selected as trigger", :green, :italicized
|
42
|
+
payload = {}
|
43
|
+
auto_opts = {}
|
44
|
+
unless args.count.zero?
|
45
|
+
args.each do |arg|
|
46
|
+
test = arg.split(':')
|
47
|
+
auto_opts[test[0].to_sym] = test[1]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Legion::JSON.load(trigger_function.values[:args]).each do |arg, required|
|
52
|
+
next if %w[args payload opts options].include? arg.to_s
|
53
|
+
|
54
|
+
if auto_opts.key? arg
|
55
|
+
payload[arg.to_sym] = auto_opts[arg]
|
56
|
+
next
|
57
|
+
end
|
58
|
+
response = ask "#{required == 'keyreq' ? '[required]' : '[optional]'} #{arg} value:"
|
59
|
+
if response.empty? && required == 'keyreq'
|
60
|
+
say "Error! #{arg} is required and cannot be empty", :red
|
61
|
+
redo
|
62
|
+
end
|
63
|
+
payload[arg.to_sym] = response unless response.empty?
|
64
|
+
end
|
65
|
+
|
66
|
+
status = options[:delay].zero? ? 'task.queued' : 'task.delayed'
|
67
|
+
task = generate_task_id(function_id: trigger_function.values[:id], status: status, runner_id: trigger_runner.values[:id], args: payload,
|
68
|
+
delay: options[:delay])
|
69
|
+
|
70
|
+
unless options[:delay].zero?
|
71
|
+
say "Task: #{task[:task_id]} is queued and will be run in #{options[:delay]}s"
|
72
|
+
return true
|
73
|
+
end
|
74
|
+
|
75
|
+
routing_key = "#{trigger_extension.values[:exchange]}.#{trigger_runner.values[:queue]}.#{trigger_function.values[:name]}"
|
76
|
+
exchange = Legion::Transport::Messages::Dynamic.new(function: trigger_function.values[:name], function_id: trigger_function.values[:id],
|
77
|
+
routing_key: routing_key, args: payload)
|
78
|
+
exchange.options[:task_id] = task[:task_id]
|
79
|
+
exchange.publish if options[:delay].zero?
|
80
|
+
|
81
|
+
say "Task: #{task[:task_id]} was queued"
|
82
|
+
end
|
83
|
+
remove_command :generate_task_id
|
84
|
+
|
85
|
+
default_task :queue
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/legion/extensions.rb
CHANGED
@@ -54,6 +54,7 @@ module Legion
|
|
54
54
|
next
|
55
55
|
end
|
56
56
|
@loaded_extensions.push(extension)
|
57
|
+
sleep(0.1)
|
57
58
|
end
|
58
59
|
Legion::Logging.info "#{@extensions.count} extensions loaded with subscription:#{@subscription_tasks.count},every:#{@timer_tasks.count},poll:#{@poll_tasks.count},once:#{@once_tasks.count},loop:#{@loop_tasks.count}"
|
59
60
|
end
|
@@ -62,6 +63,21 @@ module Legion
|
|
62
63
|
return unless gem_load(values[:gem_name], extension)
|
63
64
|
|
64
65
|
extension = Kernel.const_get(values[:extension_class])
|
66
|
+
if extension.data_required? && Legion::Settings[:data][:connected] == false
|
67
|
+
Legion::Logging.warn "#{values[:extension_name]} requires Legion::Data but isn't enabled, skipping"
|
68
|
+
return false
|
69
|
+
end
|
70
|
+
|
71
|
+
if extension.cache_required? && Legion::Settings[:cache][:connected] == false
|
72
|
+
Legion::Logging.warn "#{values[:extension_name]} requires Legion::Cache but isn't enabled, skipping"
|
73
|
+
return false
|
74
|
+
end
|
75
|
+
|
76
|
+
if extension.vault_required? && Legion::Settings[:crypt][:vault][:connected] == false
|
77
|
+
Legion::Logging.warn "#{values[:extension_name]} requires Legion::Crypt::Vault but isn't enabled, skipping"
|
78
|
+
return false
|
79
|
+
end
|
80
|
+
|
65
81
|
has_logger = extension.respond_to?(:log)
|
66
82
|
extension.autobuild
|
67
83
|
|
@@ -109,6 +125,8 @@ module Legion
|
|
109
125
|
actor_class.new
|
110
126
|
end
|
111
127
|
|
128
|
+
return if extension_hash[:running_class].respond_to?(:enabled?) && !extension_hash[:running_class].enabled?
|
129
|
+
|
112
130
|
if actor_class.ancestors.include? Legion::Extensions::Actors::Every
|
113
131
|
@timer_tasks.push(extension_hash)
|
114
132
|
elsif actor_class.ancestors.include? Legion::Extensions::Actors::Once
|
@@ -158,13 +176,19 @@ module Legion
|
|
158
176
|
extension_class: "Legion::Extensions::#{lex[1].split('_').collect(&:capitalize).join}" }
|
159
177
|
end
|
160
178
|
|
179
|
+
enabled = 0
|
180
|
+
requested = 0
|
181
|
+
|
161
182
|
Legion::Settings[:extensions].each do |extension, values|
|
162
183
|
next if @extensions.key? extension.to_s
|
163
184
|
next if values[:enabled] == false
|
185
|
+
|
186
|
+
requested += 1
|
164
187
|
next if values[:auto_install] == false
|
188
|
+
next if ENV['_'].include? 'bundle'
|
165
189
|
|
166
190
|
Legion::Logging.warn "#{extension} is missing, attempting to install automatically.."
|
167
|
-
install = Gem.install("lex-#{extension}")
|
191
|
+
install = Gem.install("lex-#{extension}", values[:version])
|
168
192
|
Legion::Logging.debug(install)
|
169
193
|
lex = Gem::Specification.find_by_name("lex-#{extension}")
|
170
194
|
|
@@ -176,9 +200,19 @@ module Legion
|
|
176
200
|
extension_class: "Legion::Extensions::#{extension.to_s.split('_').collect(&:capitalize).join}"
|
177
201
|
}
|
178
202
|
|
203
|
+
enabled += 1
|
204
|
+
|
179
205
|
rescue StandardError, Gem::MissingSpecError => e
|
180
206
|
Legion::Logging.error "Failed to auto install #{extension}, e: #{e.message}"
|
181
207
|
end
|
208
|
+
return true if requested == enabled
|
209
|
+
|
210
|
+
Legion::Logging.warn "A total of #{requested - enabled} where skipped"
|
211
|
+
if ENV.key?('_') && ENV['_'].include?('bundle')
|
212
|
+
Legion::Logging.warn 'Please add them to your Gemfile since you are using bundler'
|
213
|
+
else
|
214
|
+
Legion::Logging.warn 'You must have auto_install_missing_lex set to true to auto install missing extensions'
|
215
|
+
end
|
182
216
|
end
|
183
217
|
end
|
184
218
|
end
|
@@ -39,7 +39,7 @@ module Legion
|
|
39
39
|
@messages = {}
|
40
40
|
build_settings
|
41
41
|
build_transport
|
42
|
-
build_data
|
42
|
+
build_data if Legion::Settings[:data][:connected] && data_required?
|
43
43
|
build_helpers
|
44
44
|
build_runners
|
45
45
|
build_actors
|
@@ -61,9 +61,13 @@ module Legion
|
|
61
61
|
false
|
62
62
|
end
|
63
63
|
|
64
|
+
def vault_required?
|
65
|
+
false
|
66
|
+
end
|
67
|
+
|
64
68
|
def build_data
|
65
69
|
auto_generate_data
|
66
|
-
|
70
|
+
lex_class::Data.build
|
67
71
|
end
|
68
72
|
|
69
73
|
def build_transport
|
@@ -117,9 +121,10 @@ module Legion
|
|
117
121
|
def auto_generate_data
|
118
122
|
require 'legion/extensions/data'
|
119
123
|
log.debug 'running meta magic to generate a data base class'
|
120
|
-
return if Kernel.const_defined? "#{lex_class}::Data"
|
121
|
-
|
122
124
|
Kernel.const_get(lex_class.to_s).const_set('Data', Module.new { extend Legion::Extensions::Data })
|
125
|
+
rescue StandardError => e
|
126
|
+
log.error e.message
|
127
|
+
log.error e.backtrace
|
123
128
|
end
|
124
129
|
end
|
125
130
|
end
|
@@ -8,7 +8,7 @@ module Legion
|
|
8
8
|
alias extension_class lex_class
|
9
9
|
|
10
10
|
def lex_name
|
11
|
-
@lex_name ||= calling_class_array[2].gsub(/(?<!^)[A-Z]/) { "_#{
|
11
|
+
@lex_name ||= calling_class_array[2].gsub(/(?<!^)[A-Z]/) { "_#{Regexp.last_match(0)}" }.downcase
|
12
12
|
end
|
13
13
|
alias extension_name lex_name
|
14
14
|
alias lex_filename lex_name
|
@@ -30,7 +30,7 @@ module Legion
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def actor_name
|
33
|
-
@actor_name ||= calling_class_array.last.gsub(/(?<!^)[A-Z]/) { "_#{
|
33
|
+
@actor_name ||= calling_class_array.last.gsub(/(?<!^)[A-Z]/) { "_#{Regexp.last_match(0)}" }.downcase
|
34
34
|
end
|
35
35
|
|
36
36
|
def actor_const
|
@@ -42,7 +42,7 @@ module Legion
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def runner_name
|
45
|
-
@runner_name ||= runner_class.to_s.split('::').last.gsub(/(?<!^)[A-Z]/) { "_#{
|
45
|
+
@runner_name ||= runner_class.to_s.split('::').last.gsub(/(?<!^)[A-Z]/) { "_#{Regexp.last_match(0)}" }.downcase
|
46
46
|
end
|
47
47
|
|
48
48
|
def runner_const
|
@@ -2,22 +2,19 @@ module Legion
|
|
2
2
|
module Extensions
|
3
3
|
module Helpers
|
4
4
|
module Logger
|
5
|
-
def log
|
5
|
+
def log
|
6
6
|
return @log unless @log.nil?
|
7
7
|
|
8
8
|
logger_hash = { lex: lex_filename || nil }
|
9
9
|
logger_hash[:lex] = lex_filename.first if logger_hash[:lex].is_a? Array
|
10
10
|
if respond_to?(:settings) && settings.key?(:logger)
|
11
|
-
logger_hash[:level] = settings[:logger]
|
12
|
-
logger_hash[:
|
13
|
-
logger_hash[:level] = 'info' unless settings[:logger].key? :log_file
|
11
|
+
logger_hash[:level] = settings[:logger].key?(:level) ? settings[:logger][:level] : 'info'
|
12
|
+
logger_hash[:log_file] = settings[:logger][:log_file] if settings[:logger].key? :log_file
|
14
13
|
logger_hash[:trace] = settings[:logger][:trace] if settings[:logger].key? :trace
|
15
14
|
logger_hash[:extended] = settings[:logger][:extended] if settings[:logger].key? :extended
|
16
15
|
elsif respond_to?(:settings)
|
17
16
|
Legion::Logging.warn Legion::Settings[:extensions][lex_filename.to_sym]
|
18
17
|
Legion::Logging.warn "#{lex_name} has settings but no :logger key"
|
19
|
-
else
|
20
|
-
Legion::Logging.warn 'no settings'
|
21
18
|
end
|
22
19
|
@log = Legion::Logging::Logger.new(**logger_hash)
|
23
20
|
end
|
@@ -30,7 +30,7 @@ module Legion
|
|
30
30
|
return true
|
31
31
|
end
|
32
32
|
rescue StandardError => e
|
33
|
-
log.
|
33
|
+
log.debug("task_update failed, reverting to rmq message, e: #{e.message}")
|
34
34
|
end
|
35
35
|
|
36
36
|
update_hash = { task_id: task_id, status: status }
|
data/lib/legion/lex.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'legion/cli/version'
|
3
|
+
require 'legion/cli/lex/actor'
|
4
|
+
require 'legion/cli/lex/exchange'
|
5
|
+
require 'legion/cli/lex/message'
|
6
|
+
require 'legion/cli/lex/queue'
|
7
|
+
require 'legion/cli/lex/runner'
|
8
|
+
|
9
|
+
module Legion
|
10
|
+
class Cli
|
11
|
+
class LexBuilder < Thor
|
12
|
+
check_unknown_options!
|
13
|
+
include Thor::Actions
|
14
|
+
|
15
|
+
no_commands do
|
16
|
+
def lex
|
17
|
+
Dir.pwd.split('/').last.split('-').last
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.exit_on_failure?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.source_root
|
26
|
+
File.dirname(__FILE__)
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'actor', 'creates and manages actors'
|
30
|
+
subcommand 'actor', Legion::Cli::Lex::Actor
|
31
|
+
|
32
|
+
desc 'exchange', 'creates and manages exchanges'
|
33
|
+
subcommand 'exchange', Legion::Cli::Lex::Exchange
|
34
|
+
|
35
|
+
desc 'messages', 'creates and manages messages'
|
36
|
+
subcommand 'message', Legion::Cli::Lex::Message
|
37
|
+
|
38
|
+
desc 'queue', 'creates and manages queues'
|
39
|
+
subcommand 'queue', Legion::Cli::Lex::Queue
|
40
|
+
|
41
|
+
desc 'runner', 'creates and manages runners'
|
42
|
+
subcommand 'runner', Legion::Cli::Lex::Runner
|
43
|
+
|
44
|
+
desc 'version', 'Display Version'
|
45
|
+
map %w[-v --version] => :version
|
46
|
+
def version
|
47
|
+
say "Legion::CLI #{Legion::Cli::VERSION}"
|
48
|
+
end
|
49
|
+
|
50
|
+
method_option rspec: true
|
51
|
+
method_option pipeline: true
|
52
|
+
method_option git_init: true
|
53
|
+
method_option bundle_install: true
|
54
|
+
desc 'create :name', 'creates a new lex'
|
55
|
+
def create(name)
|
56
|
+
if Dir.pwd.include?('lex-')
|
57
|
+
say('already inside a lex_gen, try moving to a different directory', :red)
|
58
|
+
return nil
|
59
|
+
end
|
60
|
+
|
61
|
+
vars = { filename: "lex-#{name}", class_name: name.capitalize, lex: name }
|
62
|
+
filename = vars[:filename]
|
63
|
+
template('cli/lex/templates/base/gemspec.erb', "#{filename}/#{filename}.gemspec", vars)
|
64
|
+
template('cli/lex/templates/base/gemfile.erb', "#{filename}/Gemfile", vars)
|
65
|
+
template('cli/lex/templates/base/gitignore.erb', "#{filename}/.gitignore", vars)
|
66
|
+
template('cli/lex/templates/base/lic.erb', "#{filename}/LICENSE.txt", vars)
|
67
|
+
template('cli/lex/templates/base/rakefile.erb', "#{filename}/Rakefile", vars)
|
68
|
+
template('cli/lex/templates/base/rubocop.yml.erb', "#{filename}/.rubocop.yml", vars)
|
69
|
+
template('cli/lex/templates/base/readme.md.erb', "#{filename}/README.md", **vars)
|
70
|
+
template('cli/lex/templates/base/lex.erb', "#{filename}/lib/legion/extensions/#{name}.rb", vars)
|
71
|
+
template('cli/lex/templates/base/version.erb', "#{filename}/lib/legion/extensions/#{name}/version.rb", vars)
|
72
|
+
template('cli/lex/templates/base/bitbucket.yml.erb', "#{filename}/bitbucket-pipelines.yml", vars) if options[:pipeline]
|
73
|
+
template('cli/lex/templates/base/spec_helper.rb.erb', "#{filename}/spec/spec_helper.rb", vars)
|
74
|
+
template('cli/lex/templates/base/lex_spec.erb', "#{filename}/spec/legion/#{name}_spec.rb", vars)
|
75
|
+
|
76
|
+
return if !options[:git_init] && !options[:bundle_install]
|
77
|
+
|
78
|
+
run("cd lex_gen-#{filename}")
|
79
|
+
if options[:git_init]
|
80
|
+
run('git init')
|
81
|
+
run('git add .')
|
82
|
+
run('git commit -m \'Initial commit\'')
|
83
|
+
end
|
84
|
+
|
85
|
+
run('bundle update') if options[:bundle_install]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|