|
|
|
require 'uri'
|
|
|
|
|
|
|
|
class Cask; end
|
|
|
|
class Cask::CLI; end
|
|
|
|
|
|
|
|
libdir = File.dirname(__FILE__)
|
|
|
|
rubyfiles = Dir[File.join(libdir, '**', '*.rb')]
|
|
|
|
rubyfiles.each do |file|
|
|
|
|
require file.sub(/^#{libdir}\/(.*).rb$/, '\1')
|
|
|
|
end
|
|
|
|
|
|
|
|
class Cask
|
|
|
|
include Cask::Actions
|
|
|
|
include Cask::DSL
|
|
|
|
include Cask::Scopes
|
|
|
|
|
|
|
|
def self.tapspath
|
|
|
|
HOMEBREW_PREFIX.join "Library", "Taps"
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.caskroom
|
|
|
|
HOMEBREW_PREFIX.join "Caskroom"
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.appdir
|
|
|
|
@appdir ||= Pathname.new(File.expand_path("~/Applications"))
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.appdir=(_appdir)
|
|
|
|
@appdir = _appdir
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.default_tap
|
|
|
|
@default_tap ||= 'phinze-cask'
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.default_tap=(_tap)
|
|
|
|
@default_tap = _tap
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.init
|
|
|
|
HOMEBREW_CACHE.mkpath unless HOMEBREW_CACHE.exist?
|
|
|
|
caskroom.mkpath unless caskroom.exist?
|
|
|
|
appdir.mkpath unless appdir.exist?
|
|
|
|
end
|
|
|
|
|
Add tap support to `edit` and `list`
Most notably, Cask.all returns an array of strings,
not of Cask instances. This makes things easier, as
well as faster, as there's no need to run map(&:to_s)
everywhere anymore.
self.path is a utility method which returns the path
of the cask from its title. There's something subtle
going in there:
- If `cask_title` is fully qualified, e.g.
"phinze-cask/alfred", it's straightforward.
- If `cask_title` is only the name, e.g.
"firefox-aurora", the name is matched from
the full list (self.all) (which isn't sorted)
and the first result is returned.
Hence, self.path with only the name is not precise.
There might be the possibility to apply heuristics
to do a better match (prefer phinze-cask, or maybe
installed casks?) but that's for another issue :-)
self.nice_listing is another utility method used
in `search` and `list`. It returns a list where
unique casks don't have a prefix, and duplicates
do. The prefix is the tap name. The list is then
sorted. For an example or two, look at the first
comment on phinze/#12.
13 years ago
|
|
|
def self.path(cask_title)
|
|
|
|
if cask_title.include?('/')
|
|
|
|
cask_with_tap = cask_title
|
|
|
|
else
|
|
|
|
cask_with_tap = all_titles.grep(/#{cask_title}$/).first
|
|
|
|
end
|
|
|
|
|
|
|
|
if cask_with_tap
|
|
|
|
tap, cask = cask_with_tap.split('/')
|
|
|
|
tapspath.join(tap, 'Casks', "#{cask}.rb")
|
|
|
|
else
|
|
|
|
tapspath.join(default_tap, 'Casks', "#{cask_title}.rb")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.load(cask_title)
|
|
|
|
cask_path = path(cask_title)
|
|
|
|
unless cask_path.exist?
|
|
|
|
raise CaskUnavailableError, cask_title
|
|
|
|
end
|
|
|
|
require cask_path
|
|
|
|
const_get(cask_title.split('/').last.split('-').map(&:capitalize).join).new
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.title
|
|
|
|
self.name.gsub(/([a-zA-Z\d])([A-Z])/,'\1-\2').gsub(/([a-zA-Z\d])([A-Z])/,'\1-\2').downcase
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :title
|
|
|
|
def initialize(title=self.class.title)
|
|
|
|
@title = title
|
|
|
|
end
|
|
|
|
|
|
|
|
def destination_path
|
|
|
|
self.class.caskroom.join(self.title).join(self.version)
|
|
|
|
end
|
|
|
|
|
|
|
|
def installed?
|
|
|
|
destination_path.exist?
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
@title
|
|
|
|
end
|
|
|
|
end
|