From 0cb608a80c91490d50ec92a07a71c65f301ac906 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sun, 31 Mar 2024 19:47:42 -0700 Subject: [PATCH] Port Homebrew::Cmd::Migrate --- Library/Homebrew/cmd/migrate.rb | 62 +++++++++++------------ Library/Homebrew/test/cmd/migrate_spec.rb | 3 +- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Library/Homebrew/cmd/migrate.rb b/Library/Homebrew/cmd/migrate.rb index 0552ea5e0b..7f24aa820e 100644 --- a/Library/Homebrew/cmd/migrate.rb +++ b/Library/Homebrew/cmd/migrate.rb @@ -1,43 +1,43 @@ -# typed: true +# typed: strict # frozen_string_literal: true +require "abstract_command" require "migrator" -require "cli/parser" require "cask/migrator" module Homebrew - sig { returns(CLI::Parser) } - def self.migrate_args - Homebrew::CLI::Parser.new do - description <<~EOS - Migrate renamed packages to new names, where are old names of - packages. - EOS - switch "-f", "--force", - description: "Treat installed and provided as if they are from " \ - "the same taps and migrate them anyway." - switch "-n", "--dry-run", - description: "Show what would be migrated, but do not actually migrate anything." - switch "--formula", "--formulae", - description: "Only migrate formulae." - switch "--cask", "--casks", - description: "Only migrate casks." + module Cmd + class Migrate < AbstractCommand + cmd_args do + description <<~EOS + Migrate renamed packages to new names, where are old names of + packages. + EOS + switch "-f", "--force", + description: "Treat installed and provided as if they are from " \ + "the same taps and migrate them anyway." + switch "-n", "--dry-run", + description: "Show what would be migrated, but do not actually migrate anything." + switch "--formula", "--formulae", + description: "Only migrate formulae." + switch "--cask", "--casks", + description: "Only migrate casks." - conflicts "--formula", "--cask" + conflicts "--formula", "--cask" - named_args [:installed_formula, :installed_cask], min: 1 - end - end + named_args [:installed_formula, :installed_cask], min: 1 + end - def self.migrate - args = migrate_args.parse - - args.named.to_formulae_and_casks(warn: false).each do |formula_or_cask| - case formula_or_cask - when Formula - Migrator.migrate_if_needed(formula_or_cask, force: args.force?, dry_run: args.dry_run?) - when Cask::Cask - Cask::Migrator.migrate_if_needed(formula_or_cask, dry_run: args.dry_run?) + sig { override.void } + def run + args.named.to_formulae_and_casks(warn: false).each do |formula_or_cask| + case formula_or_cask + when Formula + Migrator.migrate_if_needed(formula_or_cask, force: args.force?, dry_run: args.dry_run?) + when Cask::Cask + Cask::Migrator.migrate_if_needed(formula_or_cask, dry_run: args.dry_run?) + end + end end end end diff --git a/Library/Homebrew/test/cmd/migrate_spec.rb b/Library/Homebrew/test/cmd/migrate_spec.rb index 3292d247b3..0e592a3f03 100644 --- a/Library/Homebrew/test/cmd/migrate_spec.rb +++ b/Library/Homebrew/test/cmd/migrate_spec.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true +require "cmd/migrate" require "cmd/shared_examples/args_parse" -RSpec.describe "brew migrate" do +RSpec.describe Homebrew::Cmd::Migrate do it_behaves_like "parseable arguments" it "migrates a renamed Formula", :integration_test do