#!/usr/bin/env ruby require 'elasticsearch-embedded' require 'optparse' cluster = Elasticsearch::Embedded::Cluster.new OptionParser.new do |opts| opts.on '-w', '--working-dir=WORKING_DIR', 'Elasticsearch working directory (default: `Dir.tmpdir` or `Rails.root.join("tmp")` within rails applications)' do |wd| cluster.working_dir = File.expand_path(wd) end opts.on '-p', '--port=PORT', Integer, 'Port on which to run elasticsearch (default: 9250)' do |p| cluster.port = p end opts.on '-c', '--cluster-name=NAME', 'Cluster name (default: elasticsearch_test)' do |cn| cluster.cluster_name = cn end opts.on '-n', '--nodes=NODES', Integer, 'Number of nodes started in the cluster (default: 1)' do |n| cluster.nodes = n end opts.on '--timeout=TIMEOUT', Integer, 'Timeout when starting the cluster (default: 30)' do |t| cluster.timeout = t end opts.on '-l', '--log-level=LEVEL', "Logger verbosity, numbers allowed (1..5) or level names (#{Logging::LEVELS.keys.join(', ')})" do |l| ::Elasticsearch::Embedded.verbosity(l) end opts.on '-q', '--quiet', 'Disable stdout logging' do ::Elasticsearch::Embedded.mute! end opts.on '-S', '--show-es-output', 'Enable elasticsearch output in stdout' do cluster.verbose = true end opts.on '-V VERSION', "Elasticsearch version to use (default #{Elasticsearch::Embedded::Downloader::DEFAULT_VERSION})" do |v| cluster.version = v end opts.on '-P', 'Configure cluster to persist data across restarts' do |p| cluster.persistent = !!p end opts.on_tail '-h', '--help', 'Show this message' do puts opts exit end opts.on_tail '-v', '--version', 'Show gem version' do puts "Gem version: #{Elasticsearch::Embedded::VERSION}" puts "Elasticsearch version: #{cluster.version}" exit end end.parse! # Forward additional arguments to elasticsearch cluster.additional_options = ARGV.join(' ') unless ARGV.empty? # Start the cluster cluster.start_and_wait!