diff --git a/USAGE.md b/USAGE.md index 7b684782d..9e766be02 100644 --- a/USAGE.md +++ b/USAGE.md @@ -68,16 +68,36 @@ This will both uninstall and unlink the Cask. ## Options -You can set options on the command-line and/or using the `HOMEBREW_CASK_OPTS` environment variable, e.g. (again, using google-chrome): +You can provide a number of options to the `brew cask` command to modify the default +installation locations. + +* `--caskroom=/my/path` determines where the actual applications will be located. +Default is `/opt/homebrew-cask/Caskroom` +* `--appdir=/my/path` changes the path where the symlinks to the applications (above) +will be generated. This is commonly used to create the links in the _root_ Applications directory +instead of the _home_ Applications directory by specifying `--appdir=/Applications`. Default is `~/Applications`. +* `--prefpanedir=/my/path` changes the path for PreferencePane symlinks. +Default is `~/Library/PreferencePanes` +* `--qlplugindir=/my/path` changes the path for Quicklook Plugin symlinks. +Default is `~/Library/QuickLook` +* `--widgetdir=/my/path` changes the path for Dashboard Widget symlinks. +Default is `~/Library/Widgets` +* `--fontdir=/my/path` changes the path for Fonts symlinks. +Default is `~/Library/Fonts` + +To make these changes permanent, you might want to add the following line to your `.bash_profile` or `.zshenv`: ```bash -# This probably should happen in your ~/.{ba|z}shrc -$ export HOMEBREW_CASK_OPTS="--appdir=/Applications" +# Specify your defaults in this environment variable +export HOMEBREW_CASK_OPTS="--appdir=/Applications --caskroom=/etc/Caskroom" +``` -# Installs app links to /Applications -$ brew cask install google-chrome +Note that you still can override the environment variable `HOMEBREW_CASK_OPTS` by _explicitly_ providing +the options in the command line: -# Trumps the ENV and installs app links to ~/Applications +```bash +# Will force the Chrome app to be linked to ~/Applications +# even though HOMEBREW_CASK_OPTS specified /Applications $ brew cask install --appdir="~/Applications" google-chrome ``` diff --git a/lib/cask/cli.rb b/lib/cask/cli.rb index 41329db8f..efa43ab78 100644 --- a/lib/cask/cli.rb +++ b/lib/cask/cli.rb @@ -58,7 +58,11 @@ class Cask::CLI end def self.parser + # If you modify these arguments, please update USAGE.md @parser ||= OptionParser.new do |opts| + opts.on("--caskroom=MANDATORY") do |v| + Cask.caskroom = Pathname(v).expand_path + end opts.on("--appdir=MANDATORY") do |v| Cask.appdir = Pathname(v).expand_path end diff --git a/test/cask/cli_test.rb b/test/cask/cli_test.rb index a67210d2d..eb4b6524f 100644 --- a/test/cask/cli_test.rb +++ b/test/cask/cli_test.rb @@ -74,6 +74,28 @@ describe Cask::CLI do custom_qlplugin_dir.directory?.must_equal true end + it "respects the ENV variable when choosing a non-default Caskroom location" do + default_caskroom_dir = Cask.caskroom + default_caskroom_dir.rmdir + custom_caskroom_dir = Pathname(Dir.mktmpdir('custom_caskroom_dir')) + custom_caskroom_dir.rmdir + + default_caskroom_dir.directory?.must_equal false + custom_caskroom_dir.directory?.must_equal false + + begin + ENV['HOMEBREW_CASK_OPTS'] = "--caskroom=#{custom_caskroom_dir}" + shutup { + Cask::CLI.process('list') + } + ensure + ENV.delete 'HOMEBREW_CASK_OPTS' + end + + default_caskroom_dir.directory?.must_equal false + custom_caskroom_dir.directory?.must_equal true + end + it "exits with a status of 1 when something goes wrong" do Cask::CLI.expects(:exit).with(1) Cask::CLI.expects(:lookup_command).raises(CaskError)