#!/usr/bin/env ruby

require 'bundler'
Bundler.load

require 'irb'
require 'getoptlong'
require 'esqueues-me'

opts = GetoptLong.new(
  ['--scheme', '-s', GetoptLong::REQUIRED_ARGUMENT],
  ['--host', '-h', GetoptLong::REQUIRED_ARGUMENT],
  ['--port', '-p', GetoptLong::REQUIRED_ARGUMENT],
  ['--user', '-u', GetoptLong::REQUIRED_ARGUMENT],
  ['--password', '-a', GetoptLong::REQUIRED_ARGUMENT],
  ['--help', '-e', GetoptLong::NO_ARGUMENT]
)

scheme = 'http'
host = '127.0.0.1'
port = '19600'
user = 'es_test_user'
password = 'es_test_password_1029384756'

opts.each do |opt, arg|
  case opt
  when '--scheme'
    scheme = arg if arg.presence
  when '--host'
    host = arg if arg.presence
  when '--port'
    port = arg if arg.presence
  when '--user'
    user = arg if arg.presence
  when '--password'
    password = arg if arg.presence
  when '--help'
    puts "Usage: #{$0} [options]"
    puts
    puts '  --scheme=scheme | -s ES scheme'
    puts '  --host=host | -h ES host'
    puts '  --port=port | -p ES port'
    puts '  --user=user | -u ES user'
    puts '  --password=password | -a ES password'
    puts '  --help | -e This help'
    puts
    exit(0)
  end
end

host_config = {
  :scheme => scheme,
  :host => host,
  :port => port,
  :user => user,
  :password => password
}

puts "Connecting to Elasticsearch using #{host_config}"
EsqueuesMe.set_config_settings(:hosts => [host_config])

puts ''
puts 'You are esqueuesed'
IRB.start
