#!/usr/bin/ruby.ruby3.4 
require_relative '../bin/optionally_run_with_bundler'
OptionallyRunWithBundler.run(ENV)

require 'benchmark'
require_cli_time = Benchmark.realtime { require "cli" }

begin
  runner = Bosh::Cli::Runner.new(ARGV.dup)

  load_threshold = 5
  if !ENV.has_key?("BOSH_CLI_SILENCE_SLOW_LOAD_WARNING") && require_cli_time > load_threshold
    err_nl
    warning sprintf("Loading the cli took %.1f seconds, consider cleaning your gem environment", require_cli_time)
    err_nl
  end

  Thread.abort_on_exception = true
  runner.run
rescue Errno::EPIPE
  puts("pipe closed, exiting...")
  exit(0)
rescue Interrupt
  puts "\nExiting..."
  exit(1)
end
