#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'kamal' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
  if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
    load(bundle_binstub)
  else
    abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
  end
end

require "rubygems"

require_relative "../lib/fizzy"
Fizzy.configure_bundle

require "bundler/setup"

if Fizzy.saas?
  gem_path = Gem::Specification.find_by_name("fizzy-saas").gem_dir
  deploy_config = File.join(gem_path, "config", "deploy.yml")

  unless ARGV.include?("-c") || ARGV.include?("--config-file")
    if ARGV.empty? || ARGV.first.start_with?("-")
      ARGV.unshift("-c", deploy_config)
    else
      ARGV.insert(1, "-c", deploy_config)
    end
  end
end

load Gem.bin_path("kamal", "kamal")
