exe/rabbitmq-spec
#!/usr/bin/env ruby
require 'cri'
require 'rabbitmq-spec'
root_cmd = Cri::Command.define do
name 'rabbitmq-spec'
usage 'rabbitmq-spec command [options]'
flag :h, :help, 'show help for rabbitmq-spec' do |_value, cmd|
puts cmd.help
exit 0
end
run do |_opts, _args, cmd|
puts cmd.help
exit 0
end
end
cmd_setup = Cri::Command.define do
name 'setup'
usage 'rabbitmq-spec setup [options]'
summary %{
Usage: rabbitmq-spec setup ./mqspec [-u 'amqp://guest:guest@localhost:5672']
Configure RabbitMQ using the mqspecs files.
If you pass a ruby file it will evaluate it.
If you pass a folder it will look for all the files finishing with "_mqspec.rb" and evaluate them.
}
required :u, :"broker-url", 'AMPQ Broker Url - Defaults to localhost:5672', argument: :required
run do |opts, args, _cmd|
opts[:'broker-url'] ||= 'amqp://guest:guest@localhost:5672'
if args.count.zero?
puts 'Please pass a folder or a file name.'
exit 0
else
paths = args.map do |target_path|
if File.file?(target_path)
target_path
else
Dir.glob("#{target_path}/**/*_mqspec.rb").reject { |file_path| File.directory? file_path }
end
end.flatten
if paths.count.zero?
puts "ERROR: No *_mqspec.rb files found."
else
puts "Parsing files:"
puts paths
RabbitMQSpec::Setup.run(files_paths: paths, url: opts[:'broker-url'])
puts "Setup finished on #{opts[:'broker-url']}'"
end
end
exit 0
end
end
root_cmd.add_command(cmd_setup)
root_cmd.run(ARGV)