Merge pull request #13 from passcod/add-cask-taps

Add support for taps
This commit is contained in:
Paul Hinze 2012-09-24 13:14:14 -07:00
commit 643b3d637b
5 changed files with 53 additions and 13 deletions

View File

@ -99,6 +99,11 @@ together.
The whole idea is to build a _community-maintained_ list of easily installable
packages, so the community part is important! Every little bit counts.
# Taps
You can add Casks to your existing (or new) taps: just create a directory named
`Casks` inside your tap, put your Casks there, and everything will just work.
# Alfred Integration
I've been using Casks along with Alfred to great effect. Just add

View File

@ -17,8 +17,8 @@ require 'cask/exceptions'
require 'plist/parser'
class Cask
def self.path
HOMEBREW_PREFIX.join("Library", "Taps", "phinze-cask", "Casks")
def self.tapspath
HOMEBREW_PREFIX.join "Library", "Taps"
end
def self.cellarpath
@ -26,12 +26,41 @@ class Cask
end
def self.all
cask_titles = path.entries.map(&:to_s).grep(/.rb$/).map { |p| p.to_s.split('.').first }
cask_titles.map { |c| self.load(c) }
cask_titles = Dir[tapspath.join("*", "Casks", "*.rb")]
cask_titles.map { |c|
# => "/usr/local/Library/Taps/example-tap/Casks/example.rb"
c.sub! /\.rb$/, ''
# => ".../example"
c = c.split("/").last 3
# => ["example-tap", "Casks", "example"]
c.delete_at 1
# => ["example-tap", "example"]
c = c.join "/"
# => "example-tap/example"
self.load c
c
}
end
def self.nice_listing(cask_list)
casks = {}
cask_list.each { |c|
repo, name = c.split "/"
casks[name] ||= []
casks[name].push repo
}
list = []
casks.each { |name,repos|
if repos.length == 1
list.push name
else
repos.each { |r| list.push [r,name].join "/" }
end
}
list.sort
end
def self.init
path.mkpath
HOMEBREW_CACHE.mkpath
HOME_APPS.mkpath
end
@ -42,12 +71,17 @@ class Cask
def homepage; self.class.homepage; end
def self.installed
self.all.select(&:installed?)
self.all.select { |c| load(c).installed? }
end
def self.path(cask_title)
cask_title = all.grep(/#{cask_title}$/).first unless cask_title =~ /\//
tapspath.join(cask_title.sub("/", "/Casks/") + ".rb") unless cask_title.nil?
end
def self.load(cask_title)
require path.join(cask_title)
const_get(cask_title.split('-').map(&:capitalize).join).new
require path cask_title
const_get(cask_title.split('/').last.split('-').map(&:capitalize).join).new
end
def self.title
@ -165,7 +199,7 @@ class Cask
def _zip?(path)
output = `file -Izb #{path}`
output.chomp == 'application/x-empty compressed-encoding=application/zip; charset=binary; charset=binary'
output.chomp.include? 'compressed-encoding=application/zip; charset=binary; charset=binary'
end
def _tar_bzip?(path)

View File

@ -1,8 +1,8 @@
class Cask::CLI::Edit
def self.run(*arguments)
cask_name, *rest = *arguments
cask_path = Cask.path.join("#{cask_name}.rb")
raise CaskUnavailableError, cask_path.basename('.rb').to_s unless cask_path.file?
cask_path = Cask.path(cask_name)
raise CaskUnavailableError, cask_name + ".rb" if cask_path.nil? || !cask_path.file?
exec_editor cask_path
end

View File

@ -1,6 +1,6 @@
class Cask::CLI::List
def self.run(*arguments)
puts Cask.installed.map(&:to_s).join("\n")
puts_columns Cask.nice_listing(Cask.installed)
end
def self.help

View File

@ -1,7 +1,8 @@
class Cask::CLI::Search
def self.run(*arguments)
search_term, *rest = *arguments
puts Cask.all.map(&:to_s).grep(/#{search_term}/).join("\n")
casks = {}
puts_columns Cask.nice_listing(Cask.all.grep(/#{search_term}/))
end
def self.help