#!/usr/bin/env ruby

require 'bosh/monitor'
require 'irb'
require 'irb/completion'

module Bosh
  module Monitor
    class Console
      include YamlHelper

      def self.start(context)
        new.start(context)
      end

      def start(_context)
        config_file = nil

        opts = OptionParser.new do |opt|
          opt.on('-c', '--config [ARG]', 'configuration file') { |c| config_file = c }
        end

        opts.parse!(ARGV)

        if config_file.nil?
          puts opts
          exit 1
        end

        puts "=> Loading #{config_file}"
        Bhm.config = load_yaml_file(config_file)

        begin
          require 'ruby-debug'
          puts '=> Debugger enabled'
        rescue LoadError
          puts '=> ruby-debug not found, debugger disabled'
        end

        puts '=> Welcome to BOSH Health Monitor console'

        IRB.start
      end
    end
  end
end

Bhm::Console.start(self)
