Skip to content

Commit

Permalink
add --force option for brew cask uninstall
Browse files Browse the repository at this point in the history
also update some related docs for verbs `install` and `uninstall`
  • Loading branch information
rolandwalker committed Sep 16, 2014
1 parent 5715851 commit d156cbf
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 8 deletions.
9 changes: 9 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ $ brew cask uninstall google-chrome
This will both uninstall the Cask and remove symlinks which were created in
`~/Applications`.

To uninstall all versions of a Cask, use `--force`:

```bash
$ brew cask uninstall --force google-chrome
```

Note that `uninstall --force` is currently imperfect. See the man page for
more information.

## Other Commands

* `info` -- displays information about the given Cask
Expand Down
24 changes: 19 additions & 5 deletions doc/src/brew-cask.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ names, and other aspects of this manual are still subject to change.

## FREQUENTLY USED COMMANDS

* `install` <Cask>:
* `install [--force]` <Cask>:
Install <Cask>.

* `uninstall` <Cask>:
* `uninstall [--force]` <Cask>:
Uninstall <Cask>.

* `search` <text> | /<regexp>/:
Expand Down Expand Up @@ -74,7 +74,8 @@ names, and other aspects of this manual are still subject to change.
Display information about <Cask>.

* `install [--force]` <Cask>:
Install <Cask>.
Install <Cask>. With `--force`, re-install even if the Cask appears to
be already present.

<Cask> is usually the name of a Cask as returned by `brew cask search`,
but see [OTHER WAYS TO SPECIFY A CASK][] for variations.
Expand All @@ -86,8 +87,21 @@ names, and other aspects of this manual are still subject to change.

If <Casks> are given, list the installed files for <Casks>.

* `uninstall` or `rm` or `remove` <Cask>:
Uninstall <Cask>.
* `uninstall [--force]` or `rm` or `remove` <Cask>:
Uninstall <Cask>. With `--force`, uninstall even if the Cask does
not appear to be present.

Note that `uninstall --force` is currently imperfect. It will follow
the `uninstall` instructions from *newest* Cask definition, even if
the given Cask has changed since you installed it. The result is that
`uninstall --force` will always succeed in removing relevant files
under `/opt/homebrew-cask`, but will sometimes fail to remove relevant
installed files outside of `/opt/homebrew-cask`. This issue is being
addressed.

`uninstall` without `--force` is also imperfect. It may be unable to
perform an `uninstall` operation if the given Cask has changed since you
installed it. This issue is being addressed.

* `zap` <Cask>:
Unconditionally remove _all_ files associated with <Cask>.
Expand Down
5 changes: 3 additions & 2 deletions lib/cask/cli/uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ class Cask::CLI::Uninstall < Cask::CLI::Base
def self.run(*args)
raise CaskUnspecifiedError if args.empty?
cask_names = args.reject { |a| a.chars.first == '-' }
force = args.include? '--force'
cask_names.each do |cask_name|
odebug "Uninstalling Cask #{cask_name}"
cask = Cask.load(cask_name)
raise CaskNotInstalledError.new(cask) unless cask.installed?
Cask::Installer.new(cask).uninstall
raise CaskNotInstalledError.new(cask) unless cask.installed? or force
Cask::Installer.new(cask).uninstall(force)
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/cask/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ def print_caveats
self.class.print_caveats(@cask)
end

def uninstall
def uninstall(force=false)
odebug "Cask::Installer.uninstall"
uninstall_artifacts
purge_versioned_files
purge_caskroom_path if force
end

def uninstall_artifacts
Expand Down
6 changes: 6 additions & 0 deletions test/cask/cli/uninstall_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
}.must_raise CaskNotInstalledError
end

it "tries anyway on a non-present Cask when --force is given" do
lambda {
Cask::CLI::Uninstall.run('anvil', '--force')
} # wont_raise
end

it "can uninstall and unlink multiple casks at once" do
caffeine = Cask.load('local-caffeine')
transmission = Cask.load('local-transmission')
Expand Down
24 changes: 24 additions & 0 deletions test/cask/installer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,5 +315,29 @@
(Cask.caskroom/'local-caffeine'/caffeine.version).wont_be :directory?
(Cask.caskroom/'local-caffeine').wont_be :directory?
end

it "uninstalls all versions if force is set" do
caffeine = Cask.load('local-caffeine')
installer = Cask::Installer.new(caffeine)
mutated_version = caffeine.version + '.1'

shutup do
installer.install
end

(Cask.caskroom/'local-caffeine'/caffeine.version).must_be :directory?
(Cask.caskroom/'local-caffeine'/mutated_version).wont_be :directory?
FileUtils.mv(Cask.caskroom/'local-caffeine'/caffeine.version, Cask.caskroom/'local-caffeine'/mutated_version)
(Cask.caskroom/'local-caffeine'/caffeine.version).wont_be :directory?
(Cask.caskroom/'local-caffeine'/mutated_version).must_be :directory?

shutup do
installer.uninstall(true)
end

(Cask.caskroom/'local-caffeine'/caffeine.version).wont_be :directory?
(Cask.caskroom/'local-caffeine'/mutated_version).wont_be :directory?
(Cask.caskroom/'local-caffeine').wont_be :directory?
end
end
end

0 comments on commit d156cbf

Please sign in to comment.