<commit_before>require "apiculture/cli"

class Apiculture::Cli::Main < Apiculture::Cli::Base
  desc "init [PATH]", "Initializes an Apiculture API definition"
  def init(path=".")
    if path != "." && (File.exists?(path) && !File.directory?(path))
      say "Directory '#{path}' already exists!", :red
      exit(1)
    end

    manifest = Apiculture::Manifest.new(config, File.expand_path(".")) do |m|
      m.name = ask("What is the name of the API?",
                   :default => File.basename(File.expand_path(".")))
      m.descriptor_dir = path
    end
    create_file(Apiculture::Manifest::BASE_NAME) { manifest.to_yaml }

    if path != "."
      Dir.mkdir(path)
      Dir.chdir(path)
    end
  end

  desc "generate [DEST]", "Generate SDK code"
  def generate(dest="apiculture_gen")
    if File.exists?(dest) && !File.directory?(dest)
      say "'#{dest}' is not a directory!", :red
      exit(1)
    end

    empty_directory(dest)

    old_root = destination_root

    manifest.input.invoke_protoc("java", "out.zip")

    manifest.outputs.each do |output|
      # Install the template if it doesn't exist.
      template_registry.install(output.template_uri) if output.template.nil?

      destination = File.join(dest, output.template.name)
      empty_directory(destination)
      inside destination do
        @output = output
        self.source_paths << output.template.path
        instance_exec(output, destination, &output.template.generate_proc)
        self.source_paths.delete(output.template.path)
      end
    end
  end

  desc "clean [DEST]", "Delete generated code"
  def clean(dest="apiculture_gen")
    if no?("Are you sure? (y/n)")
      say "Aborting!", :red
      exit(1)
    end
    manifest.outputs.each do |output|
      # Install the template if it doesn't exist.
      template_registry.install(output.template_uri) if output.template.nil?

      destination = File.join(dest, output.template.name)
      remove_file(destination)
    end
  end

  desc "configure [TEMPLATE_NAME]", "Configure a template (or all of them)"
  def configure(template=nil)
    manifest.outputs.each do |output|
      # Install the template if it doesn't exist.
      template_registry.install(output.template_uri) if output.template.nil?

      next if !template.nil? && output.template.name != template

      say "Configuring #{output.template.name}:"
      instance_exec output.options, &output.template.configure_options_proc
    end
    manifest.write!
  end

  desc "template SUBCOMMAND ...ARGS", "manage installed templates"
  subcommand "template", Apiculture::Cli::TemplateActions
end<commit_msg>Add separater between templates in configure action<commit_after>require "apiculture/cli"

class Apiculture::Cli::Main < Apiculture::Cli::Base
  desc "init [PATH]", "Initializes an Apiculture API definition"
  def init(path=".")
    if path != "." && (File.exists?(path) && !File.directory?(path))
      say "Directory '#{path}' already exists!", :red
      exit(1)
    end

    manifest = Apiculture::Manifest.new(config, File.expand_path(".")) do |m|
      m.name = ask("What is the name of the API?",
                   :default => File.basename(File.expand_path(".")))
      m.descriptor_dir = path
    end
    create_file(Apiculture::Manifest::BASE_NAME) { manifest.to_yaml }

    if path != "."
      Dir.mkdir(path)
      Dir.chdir(path)
    end
  end

  desc "generate [DEST]", "Generate SDK code"
  def generate(dest="apiculture_gen")
    if File.exists?(dest) && !File.directory?(dest)
      say "'#{dest}' is not a directory!", :red
      exit(1)
    end

    empty_directory(dest)

    old_root = destination_root

    manifest.input.invoke_protoc("java", "out.zip")

    manifest.outputs.each do |output|
      # Install the template if it doesn't exist.
      template_registry.install(output.template_uri) if output.template.nil?

      destination = File.join(dest, output.template.name)
      empty_directory(destination)
      inside destination do
        @output = output
        self.source_paths << output.template.path
        instance_exec(output, destination, &output.template.generate_proc)
        self.source_paths.delete(output.template.path)
      end
    end
  end

  desc "clean [DEST]", "Delete generated code"
  def clean(dest="apiculture_gen")
    if no?("Are you sure? (y/n)")
      say "Aborting!", :red
      exit(1)
    end
    manifest.outputs.each do |output|
      # Install the template if it doesn't exist.
      template_registry.install(output.template_uri) if output.template.nil?

      destination = File.join(dest, output.template.name)
      remove_file(destination)
    end
  end

  desc "configure [TEMPLATE_NAME]", "Configure a template (or all of them)"
  def configure(template=nil)
    manifest.outputs.each do |output|
      # Install the template if it doesn't exist.
      template_registry.install(output.template_uri) if output.template.nil?

      next if !template.nil? && output.template.name != template

      say "Configuring #{output.template.name}:"
      instance_exec output.options, &output.template.configure_options_proc
      say ""
    end
    manifest.write!
  end

  desc "template SUBCOMMAND ...ARGS", "manage installed templates"
  subcommand "template", Apiculture::Cli::TemplateActions
end
{'fraction_non_alphanumeric': 0.12280370300396751, 'fraction_numerical': 0.0011335726431135461, 'mean_word_length': 3.231814548361311, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1044834', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1581, 'n_words': 398}