mirror of
https://github.com/donl/homebrew-cask-versions.git
synced 2026-07-19 06:16:46 -06:00
handle fully-qualified cask names, fixes #2235
form "<user>/<repo>/<cask>" may be used on cmdline, matching homebrew - refactor Cask::Source::Tap into Cask::Source::Tapped, removing code, only handling unqualified cask names here now (ie no slash) - create Cask::Source::TappedQualified, handling "<user>-<repo>/<cask>" form as before, and new form "<user>/<repo>/<cask>", for the case that the relevant tap already exists - create Cask::Source::UntappedQualified, handling both command-line forms as above, but implicitly creating adding a new tap if it does not already exist - add module Cask::QualifiedCaskName for utility functions on qualified Cask names
This commit is contained in:
parent
990259764e
commit
b88bf787e0
6 changed files with 85 additions and 9 deletions
|
|
@ -19,6 +19,7 @@ require 'cask/link_checker'
|
|||
require 'cask/locations'
|
||||
require 'cask/pkg'
|
||||
require 'cask/pretty_listing'
|
||||
require 'cask/qualified_cask_name'
|
||||
require 'cask/scopes'
|
||||
require 'cask/source'
|
||||
require 'cask/system_command'
|
||||
|
|
|
|||
49
lib/cask/qualified_cask_name.rb
Normal file
49
lib/cask/qualified_cask_name.rb
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
module Cask::QualifiedCaskName
|
||||
def self.repo_prefix
|
||||
'homebrew-'
|
||||
end
|
||||
|
||||
def self.user_regexp
|
||||
# per https://github.com/Homebrew/homebrew/blob/4c7bc9ec3bca729c898ee347b6135ba692ee0274/Library/Homebrew/cmd/tap.rb#L121
|
||||
%r{[a-z_\-]+}
|
||||
end
|
||||
|
||||
def self.repo_regexp
|
||||
# per https://github.com/Homebrew/homebrew/blob/4c7bc9ec3bca729c898ee347b6135ba692ee0274/Library/Homebrew/cmd/tap.rb#L121
|
||||
%r{(?:#{repo_prefix})?\w+}
|
||||
end
|
||||
|
||||
def self.cask_regexp
|
||||
# per https://github.com/phinze/homebrew-cask/blob/04a8fa88c7b1d05adcd8307b9297e36f83ddbf5d/CONTRIBUTING.md#cask-name
|
||||
%r{[a-z0-9\-]+}
|
||||
end
|
||||
|
||||
def self.tap_regexp
|
||||
%r{#{user_regexp}[/\-]#{repo_regexp}}
|
||||
end
|
||||
|
||||
def self.qualified_cask_regexp
|
||||
@qualified_cask_regexp ||= %r{#{tap_regexp}/#{cask_regexp}}
|
||||
end
|
||||
|
||||
def self.parse(name)
|
||||
return nil if ! name.kind_of?(String)
|
||||
return nil if ! name.downcase.match(%r{^#{qualified_cask_regexp}$})
|
||||
path_elements = name.downcase.split('/')
|
||||
if path_elements.count == 2
|
||||
# eg phinze-cask/google-chrome.
|
||||
# Not certain this form is needed, but it was supported in the past.
|
||||
cask = path_elements[1]
|
||||
dash_elements = path_elements[0].split('-')
|
||||
repo = dash_elements.pop
|
||||
dash_elements.pop if dash_elements.count > 1 and dash_elements[-1] + '-' == repo_prefix
|
||||
user = dash_elements.join('-')
|
||||
else
|
||||
# eg phinze/cask/google-chrome
|
||||
# per https://github.com/Homebrew/homebrew/wiki/brew-tap
|
||||
user, repo, cask = path_elements
|
||||
end
|
||||
repo.sub!(%r{^#{repo_prefix}}, '')
|
||||
[user, repo, cask]
|
||||
end
|
||||
end
|
||||
|
|
@ -2,7 +2,9 @@ module Cask::Source; end
|
|||
|
||||
require 'cask/source/gone'
|
||||
require 'cask/source/path'
|
||||
require 'cask/source/tap'
|
||||
require 'cask/source/tapped_qualified'
|
||||
require 'cask/source/untapped_qualified'
|
||||
require 'cask/source/tapped'
|
||||
require 'cask/source/uri'
|
||||
|
||||
module Cask::Source
|
||||
|
|
@ -10,7 +12,9 @@ module Cask::Source
|
|||
[
|
||||
Cask::Source::URI,
|
||||
Cask::Source::Path,
|
||||
Cask::Source::Tap,
|
||||
Cask::Source::TappedQualified,
|
||||
Cask::Source::UntappedQualified,
|
||||
Cask::Source::Tapped,
|
||||
Cask::Source::Gone,
|
||||
]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,15 +1,10 @@
|
|||
class Cask::Source::Tap
|
||||
class Cask::Source::Tapped
|
||||
def self.me?(query)
|
||||
path_for_query(query).exist?
|
||||
end
|
||||
|
||||
def self.path_for_query(query)
|
||||
if query.include?('/')
|
||||
cask_with_tap = query
|
||||
else
|
||||
cask_with_tap = Cask.all_titles.find { |t| t.split('/').last == query }
|
||||
end
|
||||
|
||||
cask_with_tap = Cask.all_titles.find { |t| t.split('/').last == query }
|
||||
if cask_with_tap
|
||||
tap, cask = cask_with_tap.split('/')
|
||||
Cask.tapspath.join(tap, 'Casks', "#{cask}.rb")
|
||||
13
lib/cask/source/tapped_qualified.rb
Normal file
13
lib/cask/source/tapped_qualified.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
require 'cask/source/tapped'
|
||||
|
||||
class Cask::Source::TappedQualified < Cask::Source::Tapped
|
||||
def self.me?(query)
|
||||
!!Cask::QualifiedCaskName::parse(query) and path_for_query(query).exist?
|
||||
end
|
||||
|
||||
def self.path_for_query(query)
|
||||
user, repo, cask = Cask::QualifiedCaskName::parse(query)
|
||||
tap = "#{user}-#{repo}"
|
||||
Cask.tapspath.join(tap, 'Casks', "#{cask}.rb")
|
||||
end
|
||||
end
|
||||
14
lib/cask/source/untapped_qualified.rb
Normal file
14
lib/cask/source/untapped_qualified.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
require 'cask/source/tapped_qualified'
|
||||
require 'cmd/tap'
|
||||
|
||||
class Cask::Source::UntappedQualified < Cask::Source::TappedQualified
|
||||
def self.path_for_query(query)
|
||||
user, repo, cask = Cask::QualifiedCaskName::parse(query)
|
||||
tap = "#{user}-#{repo}"
|
||||
unless Cask.tapspath.join(tap).exist?
|
||||
ohai "Adding new tap '#{tap}'"
|
||||
Homebrew.install_tap(user, repo)
|
||||
end
|
||||
Cask.tapspath.join(tap, 'Casks', "#{cask}.rb")
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue