#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'licensee' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

Gem.use_gemdeps

version = ">= 0.a"

str = ARGV.first
if str
  str = str.b[/\A_(.*)_\z/, 1]
  if str and Gem::Version.correct?(str)
    version = str
    ARGV.shift
  end
end

path =
  if Gem.respond_to?(:activate_bin_path)
    Gem.activate_bin_path('licensee', 'licensee', version)
  else
    gem "licensee", version
    Gem.bin_path("licensee", "licensee", version)
  end

if __FILE__ == path
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'dotenv/load'
require 'thor'
require 'json'

require_relative '../lib/licensee'

class LicenseeCLI < Thor
  package_name 'Licensee'
  class_option :remote, type: :boolean, desc: 'Assume PATH is a GitHub owner/repo path'
  default_task :detect

  def self.exit_on_failure?
    true
  end

  private

  def path
    @path ||= if !options[:remote] || args.first =~ %r{^https://}
                args.first || Dir.pwd
              else
                "https://github.com/#{args.first}"
              end
  end

  def project
    @project ||= Licensee.project(path,
                                  detect_packages: options[:packages],
                                  detect_readme:   options[:readme],
                                  ref:             options[:ref])
  end

  def remote?
    path =~ %r{^https://}
  end
end

commands_dir = File.expand_path '../lib/licensee/commands/', __dir__
Dir["#{commands_dir}/*.rb"].each { |c| require(c) }

LicenseeCLI.start(ARGV)

else
  load(path)
end
