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 12 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
def installed?
return false unless destination_path.exist?
destination_path.entries.any? do |f|
f.basename.to_s =~ /.app$/
end
destination_path.exist?
end
def to_s

12
lib/cask/cli/uninstall.rb

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

10
lib/cask/installer.rb

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

17
test/cli/uninstall_test.rb

@ -23,4 +23,21 @@ describe Cask::CLI::Uninstall do
Cask::Installer.expects(:uninstall).with(fake_cask)
Cask::CLI::Uninstall.run('fake-cask')
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

Loading…
Cancel
Save