#!/usr/bin/env ruby
# vim: ft=ruby
require 'rubygems'
require 'bundler/setup'
require 'optparse'

class GeoLogCursorOptionParser
  def self.parse(argv)
    options = {}

    op = OptionParser.new
    op.banner = 'GitLab Geo: Log Cursor'
    op.separator ''
    op.separator 'Usage: ./geo_log_cursor [options]'
    op.separator ''
    op.on('-d', '--debug', 'Enable detailed logging with extra debug information') { options[:debug] = true }

    op.separator 'Common options:'
    op.on('-h', '--help') do
      puts op.to_s
      exit
    end
    op.on('-v', '--version') do
      # Load only necessary libraries for faster startup
      require "#{File.dirname(__FILE__)}/../lib/gitlab/geo/log_cursor/daemon"

      puts Gitlab::Geo::LogCursor::Daemon::VERSION
      exit
    end
    op.separator ''

    op.parse!(argv)

    options
  end
end

if $0 == __FILE__
  options = GeoLogCursorOptionParser.parse(ARGV)

  # We load rails environment / initializers only here to get faster command line startup when `--help` and `--version`
  require "#{File.dirname(__FILE__)}/../config/environment"

  Gitlab::Geo::LogCursor::Daemon.new(options).run!
end
