require "file_utils"

module Lattice
  module CLI
    # Removes the `.lattice-cache/` directory produced by the persistent index.
    class ClearCache
      DEFAULT_CACHE_DIR = ".lattice-cache"

      def self.run(cache_dir : String = DEFAULT_CACHE_DIR) : NoReturn
        if Dir.exists?(cache_dir)
          FileUtils.rm_rf(cache_dir)
          puts "Removed #{cache_dir}"
        else
          puts "Nothing to clear — '#{cache_dir}' does not exist."
        end
        exit 0
      end
    end
  end
end
