Browse Source

add brew cask uninstall

this delegates to homebrew's uninstall to get its work done. vanilla
`brew uninstall` actually works, but this gives us a more consistent
interface.

as discussed in #47
phinze 13 years ago
parent
commit
ab57da07ea
  1. 3
      lib/cask.rb
  2. 4
      lib/cask/actions.rb
  3. 12
      lib/cask/cli/install.rb
  4. 16
      lib/cask/cli/uninstall.rb
  5. 11
      lib/cask/exceptions.rb
  6. 10
      lib/cask/installer.rb
  7. 2
      test/cask/actions_test.rb
  8. 35
      test/cask/installer_test.rb
  9. 15
      test/cask_test.rb
  10. 18
      test/cli/install_test.rb
  11. 26
      test/cli/uninstall_test.rb

3
lib/cask.rb

@ -1,5 +1,3 @@
require 'download_strategy'
require 'formula_support'
require 'plist/parser'
require 'uri'
@ -8,6 +6,7 @@ class Cask; end
require 'cask/cli'
require 'cask/cli/edit'
require 'cask/cli/install'
require 'cask/cli/uninstall'
require 'cask/cli/linkapps'
require 'cask/cli/list'
require 'cask/cli/search'

4
lib/cask/actions.rb

@ -1,8 +1,4 @@
module Cask::Actions
def install
Cask::Installer.install(self)
end
def linkapps
puts "looking in #{destination_path}/**/*.app"
puts "found #{Pathname.glob("#{destination_path}/**/*.app").inspect}"

12
lib/cask/cli/install.rb

@ -1,12 +1,12 @@
class Cask::CLI::Install
def self.run(*cask_names)
cask_names.each do |cask_name|
cask = begin
Cask.load(cask_name)
rescue CaskUnavailableError => e
onoe e
end
cask.install if cask
begin
cask = Cask.load(cask_name)
Cask::Installer.install(cask)
rescue CaskUnavailableError => e
onoe e
end
end
end

16
lib/cask/cli/uninstall.rb

@ -0,0 +1,16 @@
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
end
end
def self.help
"uninstalls the cask of the given name"
end
end

11
lib/cask/exceptions.rb

@ -1,3 +1,14 @@
class CaskNotInstalledError < RuntimeError
attr_reader :cask
def initialize cask
@cask = cask
end
def to_s
"#{cask} is not installed"
end
end
class CaskUnavailableError < RuntimeError
attr_reader :name
def initialize name

10
lib/cask/installer.rb

@ -1,6 +1,7 @@
class Cask::Installer
class << self
def install(cask)
require 'formula_support'
downloader = CurlDownloadStrategy.new(cask.title, SoftwareSpec.new(cask.url.to_s, cask.version))
downloaded_path = downloader.fetch
@ -13,6 +14,15 @@ class Cask::Installer
ohai "Success! #{cask} installed to #{cask.destination_path}"
end
def uninstall(cask)
raise CaskNotInstalledError.new(cask) unless cask.installed?
require 'cmd/uninstall'
ARGV.clear
ARGV << cask.title
Homebrew.uninstall
end
def _with_extracted_mountpoints(path)
if _dmg?(path)
File.open(path) do |dmg|

2
test/cask/actions_test.rb

@ -9,7 +9,7 @@ describe Cask::Actions do
Cask.stubs(:appdir).returns(fake_appdir)
@caffeine = Cask.load('caffeine')
shutup { @caffeine.install }
shutup { Cask::Installer.install(@caffeine) }
@appdir = HOMEBREW_CELLAR/'caffeine'/@caffeine.version
@app = @appdir/'Caffeine.app'
end

35
test/cask/installer_test.rb

@ -0,0 +1,35 @@
require 'test_helper'
describe Cask::Installer do
describe "install" do
it "downloads and installs a nice fresh Cask" do
caffeine = Cask.load('caffeine')
shutup do
Cask::Installer.install(caffeine)
end
dest_path = HOMEBREW_CELLAR/'caffeine'/caffeine.version
dest_path.must_be :directory?
application = dest_path/'Caffeine.app'
application.must_be :directory?
end
end
describe "uninstall" do
it "fully uninstalls a cask" do
caffeine = Cask.load('caffeine')
shutup do
Cask::Installer.install(caffeine)
Cask::Installer.uninstall(caffeine)
end
dest_path = HOMEBREW_CELLAR/'caffeine'/caffeine.version
application = dest_path/'Caffeine.app'
application.wont_be :directory?
dest_path.wont_be :directory?
end
end
end

15
test/cask_test.rb

@ -23,21 +23,6 @@ describe Cask do
end
end
describe "install" do
it "downloads and installs a nice fresh Cask" do
caffeine = Cask.load('caffeine')
shutup do
caffeine.install
end
dest_path = HOMEBREW_CELLAR/'caffeine'/caffeine.version
dest_path.must_be :directory?
application = dest_path/'Caffeine.app'
application.must_be :directory?
end
end
describe "init" do
it "sets up dependent directories required for us to properly function" do
HOMEBREW_CACHE.stubs(:exist?).returns(false)

18
test/cli/install_test.rb

@ -2,19 +2,21 @@ require 'test_helper'
describe Cask::CLI::Install do
it "allows install of multiple casks at once" do
stub_cask = stub(:install => nil)
Cask.expects(:load).with('adium').returns(stub_cask)
Cask.expects(:load).with('google-chrome').returns(stub_cask)
Cask::Installer.stubs(:install)
Cask.expects(:load).with('adium')
Cask.expects(:load).with('google-chrome')
Cask::CLI::Install.run('adium', 'google-chrome')
end
it "properly handles casks that are not present" do
stub_cask = stub(:install => nil)
Cask.expects(:load).with('adium').returns(stub_cask)
Cask::Installer.stubs(:install)
Cask.expects(:load).with('adium')
Cask.expects(:load).with('what-the-balls').raises(CaskUnavailableError.new('what-the-balls'))
Cask.expects(:load).with('google-chrome').returns(stub_cask)
shutup do
Cask.expects(:load).with('google-chrome')
lambda {
Cask::CLI::Install.run('adium', 'what-the-balls', 'google-chrome')
end
}.must_output <<-OUTPUT.gsub(/^ */, '')
Error: No available cask for what-the-balls
OUTPUT
end
end

26
test/cli/uninstall_test.rb

@ -0,0 +1,26 @@
require 'test_helper'
describe Cask::CLI::Uninstall do
it "shows an error when a bad cask is provided" do
lambda {
Cask::CLI::Uninstall.run('notacask')
}.must_output <<-OUTPUT.gsub(/^ */, '')
Error: No available cask for notacask
OUTPUT
end
it "shows an error when a cask is provided that's not installed" do
lambda {
Cask::CLI::Uninstall.run('anvil')
}.must_output <<-OUTPUT.gsub(/^ */, '')
Error: anvil is not installed
OUTPUT
end
it "delegates to the installer to properly uninstall" do
fake_cask = stub('fake-cask')
Cask.stubs(:load).with('fake-cask').returns(fake_cask)
Cask::Installer.expects(:uninstall).with(fake_cask)
Cask::CLI::Uninstall.run('fake-cask')
end
end
Loading…
Cancel
Save