# typed: strict
# frozen_string_literal: true

require "abstract_command"
require "utils/cpan"

module Homebrew
  module DevCmd
    class UpdatePerlResources < AbstractCommand
      cmd_args do
        description <<~EOS
          Update versions for CPAN resource blocks in <formula>.
        EOS
        switch "-p", "--print-only",
               description: "Print the updated resource blocks instead of changing <formula>."
        switch "-s", "--silent",
               description: "Suppress any output.",
               odeprecated: true
        switch "--ignore-errors",
               description: "Continue processing even if some resources can't be resolved."

        named_args :formula, min: 1, without_api: true
      end

      sig { override.void }
      def run
        Homebrew.install_bundler_gems!(groups: ["ast"])

        args.named.to_formulae.each do |formula|
          CPAN.update_perl_resources! formula,
                                      print_only:    args.print_only?,
                                      quiet:         args.quiet? || args.silent?,
                                      verbose:       args.verbose?,
                                      ignore_errors: args.ignore_errors?
        end
      end
    end
  end
end
