mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Port Homebrew::Cmd::Migrate
This commit is contained in:
parent
59adde2069
commit
0cb608a80c
@ -1,43 +1,43 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "abstract_command"
|
||||||
require "migrator"
|
require "migrator"
|
||||||
require "cli/parser"
|
|
||||||
require "cask/migrator"
|
require "cask/migrator"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
sig { returns(CLI::Parser) }
|
module Cmd
|
||||||
def self.migrate_args
|
class Migrate < AbstractCommand
|
||||||
Homebrew::CLI::Parser.new do
|
cmd_args do
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
Migrate renamed packages to new names, where <formula> are old names of
|
Migrate renamed packages to new names, where <formula> are old names of
|
||||||
packages.
|
packages.
|
||||||
EOS
|
EOS
|
||||||
switch "-f", "--force",
|
switch "-f", "--force",
|
||||||
description: "Treat installed <formula> and provided <formula> as if they are from " \
|
description: "Treat installed <formula> and provided <formula> as if they are from " \
|
||||||
"the same taps and migrate them anyway."
|
"the same taps and migrate them anyway."
|
||||||
switch "-n", "--dry-run",
|
switch "-n", "--dry-run",
|
||||||
description: "Show what would be migrated, but do not actually migrate anything."
|
description: "Show what would be migrated, but do not actually migrate anything."
|
||||||
switch "--formula", "--formulae",
|
switch "--formula", "--formulae",
|
||||||
description: "Only migrate formulae."
|
description: "Only migrate formulae."
|
||||||
switch "--cask", "--casks",
|
switch "--cask", "--casks",
|
||||||
description: "Only migrate casks."
|
description: "Only migrate casks."
|
||||||
|
|
||||||
conflicts "--formula", "--cask"
|
conflicts "--formula", "--cask"
|
||||||
|
|
||||||
named_args [:installed_formula, :installed_cask], min: 1
|
named_args [:installed_formula, :installed_cask], min: 1
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def self.migrate
|
sig { override.void }
|
||||||
args = migrate_args.parse
|
def run
|
||||||
|
args.named.to_formulae_and_casks(warn: false).each do |formula_or_cask|
|
||||||
args.named.to_formulae_and_casks(warn: false).each do |formula_or_cask|
|
case formula_or_cask
|
||||||
case formula_or_cask
|
when Formula
|
||||||
when Formula
|
Migrator.migrate_if_needed(formula_or_cask, force: args.force?, dry_run: args.dry_run?)
|
||||||
Migrator.migrate_if_needed(formula_or_cask, force: args.force?, dry_run: args.dry_run?)
|
when Cask::Cask
|
||||||
when Cask::Cask
|
Cask::Migrator.migrate_if_needed(formula_or_cask, dry_run: args.dry_run?)
|
||||||
Cask::Migrator.migrate_if_needed(formula_or_cask, dry_run: args.dry_run?)
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "cmd/migrate"
|
||||||
require "cmd/shared_examples/args_parse"
|
require "cmd/shared_examples/args_parse"
|
||||||
|
|
||||||
RSpec.describe "brew migrate" do
|
RSpec.describe Homebrew::Cmd::Migrate do
|
||||||
it_behaves_like "parseable arguments"
|
it_behaves_like "parseable arguments"
|
||||||
|
|
||||||
it "migrates a renamed Formula", :integration_test do
|
it "migrates a renamed Formula", :integration_test do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user