brew cask list, when given args, list installed files

this mimics (and indeed steals code from) homebrew's behavior

refs #1417
This commit is contained in:
phinze 2013-11-03 12:23:08 -06:00
parent c0e807d863
commit a1fa264465
4 changed files with 56 additions and 5 deletions

View File

@ -18,6 +18,7 @@ require 'cask/installer'
require 'cask/link_checker'
require 'cask/locations'
require 'cask/pkg'
require 'cask/pretty_listing'
require 'cask/scopes'
require 'cask/system_command'
require 'cask/underscore_supporting_uri'

View File

@ -1,9 +1,32 @@
class Cask::CLI::List
def self.run(*arguments)
if arguments.any?
list_files(*arguments)
else
list_installed
end
end
def self.list_files(*cask_names)
cask_names.each do |cask_name|
begin
cask = Cask.load(cask_name)
if cask.installed?
Cask::PrettyListing.new(cask).print
else
opoo "#{cask} is not installed"
end
rescue CaskError => e
onoe e
end
end
end
def self.list_installed
puts_columns Cask::CLI.nice_listing(Cask.installed)
end
def self.help
"lists installed casks"
"with no args, lists installed casks; given installed casks, lists installed files"
end
end

View File

@ -0,0 +1,12 @@
require 'cmd/list' # for homebrew's ::PrettyListing
class Cask::PrettyListing
attr_reader :cask
def initialize(cask)
@cask = cask
end
def print
::PrettyListing.new(cask.destination_path)
end
end

View File

@ -1,10 +1,10 @@
require 'test_helper'
describe Cask::CLI::List do
it "lists the installed casks in a pretty fashion" do
shutup do
Cask::CLI::Install.run('local-transmission', 'local-caffeine')
end
it 'lists the installed casks in a pretty fashion' do
casks = %w[local-caffeine local-transmission].map { |c| Cask.load(c) }
casks.each { |c| TestHelper.install_without_artifacts(c) }
lambda {
Cask::CLI::List.run
@ -13,4 +13,19 @@ describe Cask::CLI::List do
local-transmission
OUTPUT
end
it 'given a set of installed casks, lists the installed files for those casks' do
casks = %w[local-caffeine local-transmission].map { |c| Cask.load(c) }
casks.each { |c| TestHelper.install_without_artifacts(c) }
caffeine, transmission = casks
lambda {
Cask::CLI::List.run('local-transmission', 'local-caffeine')
}.must_output <<-OUTPUT.gsub(/^ */, '')
#{transmission.destination_path}/Transmission.app/Contents/ (489 files)
#{caffeine.destination_path}/Caffeine.app/Contents/ (13 files)
OUTPUT
end
end