Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add brew cask --prefix [cask] command #8677

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/hbc/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Hbc::CLI; end
require 'hbc/cli/info'
require 'hbc/cli/install'
require 'hbc/cli/list'
require 'hbc/cli/prefix'
require 'hbc/cli/search'
require 'hbc/cli/uninstall'
require 'hbc/cli/update'
Expand Down
29 changes: 29 additions & 0 deletions lib/hbc/cli/prefix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Hbc::CLI::Prefix < Hbc::CLI::Base
def self.run(*args)
cask_tokens = cask_tokens_from(args)
if cask_tokens.empty?
puts install_prefix
else
cask_tokens.each { |cask_token| puts cask_prefix(cask_token) }
end
end

def self.install_prefix
@install_prefix ||= Pathname.new(HOMEBREW_PREFIX).join('opt', 'brew-cask')
end

def self.cask_prefix(cask_token)
cask = Hbc.load(cask_token)
raise Hbc::CaskNotInstalledError.new(cask) unless cask.installed?
cask.staged_path
end

def self.command_name
@command_name ||= '--prefix'
end

def self.help
"with no args, displays Homebrew-cask's install path; given installed #{
}Casks, lists the locations in the Caskroom where the Casks are installed"
end
end
61 changes: 61 additions & 0 deletions test/cask/cli/prefix_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
require 'test_helper'

describe Hbc::CLI::Prefix do
describe 'given no args' do
before do
@expected_output = "#{HOMEBREW_PREFIX}/opt/brew-cask\n"
end

it 'displays the install location for Homebrew-cask' do
lambda {
Hbc::CLI::Prefix.run
}.must_output(@expected_output)
end
end

describe 'given one or more Casks' do
before do
@caffeine = Hbc.load('local-caffeine')
@transmission = Hbc.load('local-transmission')

shutup do
Hbc::Installer.new(@caffeine).install
Hbc::Installer.new(@transmission).install
end
end

after do
shutup do
Hbc::CLI::Uninstall.run('local-caffeine', 'local-transmission')
end
end

it 'displays the install location for an installed Cask' do
lambda {
Hbc::CLI::Prefix.run('local-caffeine')
}.must_output("#{@caffeine.staged_path}\n")

lambda {
Hbc::CLI::Prefix.run('local-transmission')
}.must_output("#{@transmission.staged_path}\n")
end

it 'displays the install locations for multiple installed Casks' do
lambda {
Hbc::CLI::Prefix.run('local-caffeine', 'local-transmission')
}.must_output("#{@caffeine.staged_path}\n#{@transmission.staged_path}\n")
end

it 'shows an error when a bad Cask is provided' do
lambda {
Hbc::CLI::Prefix.run('notacask')
}.must_raise Hbc::CaskUnavailableError
end

it "shows an error when a Cask is provided that's not installed" do
lambda {
Hbc::CLI::Prefix.run('anvil')
}.must_raise Hbc::CaskNotInstalledError
end
end
end