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

if File.exist?(File.expand_path("../../.git", __dir__))
  ENV["RUBYOPT"] = ENV["RUBYOPT"].to_s.sub("-rsimplecov ", "")
  ENV["RUBYLIB"] = ENV["RUBYLIB"].to_s.sub("#{File.expand_path("..", __dir__)}/lib:", "")

  gem "decidim-core"
end

case ARGV[0]
when "--component"
  ARGV.replace(["component", *ARGV[1..-1]])

  require "decidim/generators/component_generator"

  Decidim::Generators::ComponentGenerator.start
when "--version"
  require "decidim/core/version"
  puts Decidim::Core.version
when "--help"
  require "decidim/core/version"
  puts "Decidim #{Decidim::Core.version}
Syntax: decidim [options] [App or Module name]
https://decidim.org

Options:
  --help                   display this help and exit
  --version                output version information and exit
  --component [name]       creates a component for Decidim
  [name]                   creates an application based on Decidim"
else
  require "decidim/generators/app_generator"

  Decidim::Generators::AppGenerator.start
end
