global: unify tap regex.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Mike McQuaid 2013-10-21 04:24:54 +01:00
parent 862e6ca3bc
commit 077f09e4ea
3 changed files with 7 additions and 8 deletions

View File

@ -4,12 +4,6 @@ require 'utils'
require 'utils/json' require 'utils/json'
module Homebrew extend self module Homebrew extend self
# A regular expession to capture the username (one or more char but no `/`,
# which has to be escaped like `\/`), repository, followed by an optional `/`
# and an optional query.
TAP_QUERY_REGEX = /^([^\/]+)\/([^\/]+)\/?(.+)?$/
def search def search
if ARGV.include? '--macports' if ARGV.include? '--macports'
exec_browser "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}" exec_browser "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"
@ -25,7 +19,7 @@ module Homebrew extend self
exec_browser "http://packages.ubuntu.com/search?keywords=#{ARGV.next}&searchon=names&suite=all&section=all" exec_browser "http://packages.ubuntu.com/search?keywords=#{ARGV.next}&searchon=names&suite=all&section=all"
elsif (query = ARGV.first).nil? elsif (query = ARGV.first).nil?
puts_columns Formula.names puts_columns Formula.names
elsif ARGV.first =~ TAP_QUERY_REGEX elsif ARGV.first =~ HOMEBREW_TAP_REGEX
# So look for user/repo/query or list all formulae by the tap # So look for user/repo/query or list all formulae by the tap
# we downcase to avoid case-insensitive filesystem issues. # we downcase to avoid case-insensitive filesystem issues.
user, repo, query = $1.downcase, $2.downcase, $3 user, repo, query = $1.downcase, $2.downcase, $3

View File

@ -44,7 +44,7 @@ class FormulaUnavailableError < RuntimeError
end end
def to_s def to_s
if name =~ %r{(\w+)/(\w+)/([^/]+)} then <<-EOS.undent if name =~ HOMEBREW_TAP_REGEX then <<-EOS.undent
No available formula for #$3 #{dependent_s} No available formula for #$3 #{dependent_s}
Please tap it and then try again: brew tap #$1/#$2 Please tap it and then try again: brew tap #$1/#$2
EOS EOS

View File

@ -83,6 +83,11 @@ HOMEBREW_USER_AGENT = "Homebrew #{HOMEBREW_VERSION} (Ruby #{RUBY_VERSION}-#{RUBY
HOMEBREW_CURL_ARGS = '-f#LA' HOMEBREW_CURL_ARGS = '-f#LA'
# A regular expession to capture the username (one or more char but no `/`,
# which has to be escaped like `\/`), repository, followed by an optional `/`
# and an optional query.
HOMEBREW_TAP_REGEX = /^([^\/]+)\/([^\/]+)\/?(.+)?$/
module Homebrew extend self module Homebrew extend self
include FileUtils include FileUtils