Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle fully-qualified cask names, fixes #2235 #2303

Merged
merged 1 commit into from
Jan 10, 2014

Conversation

rolandwalker
Copy link
Contributor

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

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
@rolandwalker
Copy link
Contributor Author

Note, there is an alternate way to handle <user>/<repo>/<cask> when the tap does not already exist, which is to expand the Cask name to a URI (not to implicitly add the tap). Homebrew implicitly adds the tap, as described by @sonots in #2235, so I followed that logic. However, the expand-to-URI approach also has some merits, so I'm inlining a patch for that below for reference. For brevity, the diff is against the current PR, not master.

Sat Jan 4 07:31:24 2014 -0500 51b2ee5 (HEAD, qualified_cask_names_as_uris) alternate implementation of FQ cask names  [Roland Walker]
diff --git a/lib/cask/qualified_cask_name.rb b/lib/cask/qualified_cask_name.rb
index cb554a5..5b29511 100644
--- a/lib/cask/qualified_cask_name.rb
+++ b/lib/cask/qualified_cask_name.rb
@@ -46,4 +46,13 @@ module Cask::QualifiedCaskName
     repo.sub!(%r{^#{repo_prefix}}, '')
     [user, repo, cask]
   end
+
+  def self.github_raw_url
+    'https://raw.github.com'
+  end
+
+  def self.to_uri(name)
+    user, repo, cask = self.parse(name)
+    "#{github_raw_url}/#{user}/#{repo_prefix}#{repo}/master/Casks/#{cask}.rb"
+  end
 end
diff --git a/lib/cask/source/untapped_qualified.rb b/lib/cask/source/untapped_qualified.rb
index edf22ff..33df678 100644
--- a/lib/cask/source/untapped_qualified.rb
+++ b/lib/cask/source/untapped_qualified.rb
@@ -1,14 +1,11 @@
-require 'cask/source/tapped_qualified'
-require 'cmd/tap'
+require 'cask/source/uri'

-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")
+class Cask::Source::UntappedQualified < Cask::Source::URI
+  def self.me?(query)
+    !!Cask::QualifiedCaskName::parse(query)
+  end
+
+  def initialize(query)
+    @uri = Cask::QualifiedCaskName::to_uri(query)
   end
 end

@phinze
Copy link
Contributor

phinze commented Jan 10, 2014

Wow this is great work @rolandwalker! 👍

I love that this can auto-tap for you - removing a command for users to install from non-standard taps. Cool stuff. ⛵

phinze added a commit that referenced this pull request Jan 10, 2014
handle fully-qualified cask names, fixes #2235
@phinze phinze merged commit 6786f33 into Homebrew:master Jan 10, 2014
@sonots
Copy link

sonots commented Jan 11, 2014

Thank you for your great work @rolandwalker 👯

@rolandwalker rolandwalker deleted the qualified_cask_names branch February 8, 2014 21:49
@Homebrew Homebrew locked and limited conversation to collaborators May 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants