Browse Source

fix uninstall to work with multiple casks at once

homebrew does internal caching in ARGV that prevents us from doing the
`ARGV.clear; ARGV << 'newarg'` trick twice.

rather than try to further reach in to homebrew's innards, i figure it's
better to just pass multiple arguments down to homebrew code at once,
since it already supports that

refs #47
phinze 13 years ago
parent
commit
3539767745
  1. 5
      lib/cask.rb
  2. 12
      lib/cask/cli/uninstall.rb
  3. 10
      lib/cask/installer.rb
  4. 17
      test/cli/uninstall_test.rb

5
lib/cask.rb

@ -65,10 +65,7 @@ class Cask
end end
def installed? def installed?
return false unless destination_path.exist? destination_path.exist?
destination_path.entries.any? do |f|
f.basename.to_s =~ /.app$/
end
end end
def to_s def to_s

12
lib/cask/cli/uninstall.rb

@ -1,12 +1,10 @@
class Cask::CLI::Uninstall class Cask::CLI::Uninstall
def self.run(*cask_names) def self.run(*cask_names)
cask_names.each do |cask_name| begin
begin casks = cask_names.map { |cn| Cask.load(cn) }
cask = Cask.load(cask_name) Cask::Installer.uninstall(*casks)
Cask::Installer.uninstall(cask) rescue CaskUnavailableError,CaskNotInstalledError => e
rescue CaskUnavailableError,CaskNotInstalledError => e onoe e
onoe e
end
end end
end end

10
lib/cask/installer.rb

@ -14,12 +14,16 @@ class Cask::Installer
ohai "Success! #{cask} installed to #{cask.destination_path}" ohai "Success! #{cask} installed to #{cask.destination_path}"
end end
def uninstall(cask) def uninstall(*casks)
raise CaskNotInstalledError.new(cask) unless cask.installed? casks.each do |cask|
raise CaskNotInstalledError.new(cask) unless cask.installed?
end
require 'cmd/uninstall' require 'cmd/uninstall'
ARGV.clear ARGV.clear
ARGV << cask.title casks.each do |cask|
ARGV << cask.title
end
Homebrew.uninstall Homebrew.uninstall
end end

17
test/cli/uninstall_test.rb

@ -23,4 +23,21 @@ describe Cask::CLI::Uninstall do
Cask::Installer.expects(:uninstall).with(fake_cask) Cask::Installer.expects(:uninstall).with(fake_cask)
Cask::CLI::Uninstall.run('fake-cask') Cask::CLI::Uninstall.run('fake-cask')
end end
it "can uninstall multiple casks at once" do
caffeine = Cask.load('caffeine')
anvil = Cask.load('anvil')
shutup do
Cask::Installer.install(caffeine)
Cask::Installer.install(anvil)
end
shutup do
Cask::CLI::Uninstall.run('caffeine', 'anvil')
end
caffeine.wont_be :installed?
anvil.wont_be :installed?
end
end end

Loading…
Cancel
Save