From 48f4adad3318bde94e8d41f727279758fb80620c Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Mon, 1 Apr 2024 11:50:25 -0700 Subject: [PATCH] Port Homebrew::Cmd::Untap --- Library/Homebrew/cmd/untap.rb | 77 ++++++++++++------------- Library/Homebrew/test/cmd/untap_spec.rb | 3 +- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Library/Homebrew/cmd/untap.rb b/Library/Homebrew/cmd/untap.rb index b734ae04e8..f2a2547d41 100644 --- a/Library/Homebrew/cmd/untap.rb +++ b/Library/Homebrew/cmd/untap.rb @@ -1,51 +1,50 @@ # typed: strict # frozen_string_literal: true -require "cli/parser" +require "abstract_command" require "untap" module Homebrew - sig { returns(CLI::Parser) } - def self.untap_args - Homebrew::CLI::Parser.new do - description <<~EOS - Remove a tapped formula repository. - EOS - switch "-f", "--force", - description: "Untap even if formulae or casks from this tap are currently installed." + module Cmd + class UntapCmd < AbstractCommand + cmd_args do + description <<~EOS + Remove a tapped formula repository. + EOS + switch "-f", "--force", + description: "Untap even if formulae or casks from this tap are currently installed." - named_args :tap, min: 1 - end - end - - sig { void } - def self.untap - args = untap_args.parse - - args.named.to_installed_taps.each do |tap| - odie "Untapping #{tap} is not allowed" if tap.core_tap? && Homebrew::EnvConfig.no_install_from_api? - - if Homebrew::EnvConfig.no_install_from_api? || (!tap.core_tap? && !tap.core_cask_tap?) - installed_tap_formulae = Untap.installed_formulae_for(tap:) - installed_tap_casks = Untap.installed_casks_for(tap:) - - if installed_tap_formulae.present? || installed_tap_casks.present? - installed_names = (installed_tap_formulae + installed_tap_casks.map(&:token)).join("\n") - if args.force? || Homebrew::EnvConfig.developer? - opoo <<~EOS - Untapping #{tap} even though it contains the following installed formulae or casks: - #{installed_names} - EOS - else - odie <<~EOS - Refusing to untap #{tap} because it contains the following installed formulae or casks: - #{installed_names} - EOS - end - end + named_args :tap, min: 1 end - tap.uninstall manual: true + sig { override.void } + def run + args.named.to_installed_taps.each do |tap| + odie "Untapping #{tap} is not allowed" if tap.core_tap? && Homebrew::EnvConfig.no_install_from_api? + + if Homebrew::EnvConfig.no_install_from_api? || (!tap.core_tap? && !tap.core_cask_tap?) + installed_tap_formulae = Untap.installed_formulae_for(tap:) + installed_tap_casks = Untap.installed_casks_for(tap:) + + if installed_tap_formulae.present? || installed_tap_casks.present? + installed_names = (installed_tap_formulae + installed_tap_casks.map(&:token)).join("\n") + if args.force? || Homebrew::EnvConfig.developer? + opoo <<~EOS + Untapping #{tap} even though it contains the following installed formulae or casks: + #{installed_names} + EOS + else + odie <<~EOS + Refusing to untap #{tap} because it contains the following installed formulae or casks: + #{installed_names} + EOS + end + end + end + + tap.uninstall manual: true + end + end end end end diff --git a/Library/Homebrew/test/cmd/untap_spec.rb b/Library/Homebrew/test/cmd/untap_spec.rb index d7e13fffd4..ba9bb56ec4 100644 --- a/Library/Homebrew/test/cmd/untap_spec.rb +++ b/Library/Homebrew/test/cmd/untap_spec.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true require "cmd/shared_examples/args_parse" +require "cmd/untap" -RSpec.describe "brew untap" do +RSpec.describe Homebrew::Cmd::UntapCmd do it_behaves_like "parseable arguments" it "untaps a given Tap", :integration_test do