From cb711a2d39a9c76d40f43b4fe13564eba3424ea8 Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Thu, 23 Jun 2016 23:23:41 -0700 Subject: [PATCH] create: add --tap option (#389) This commit adds a --tap option to the create command such that a user could create a formula in a specified tap instead of the core. --- Library/Homebrew/cmd/create.rb | 21 +++++++++++++++------ share/doc/homebrew/brew.1.html | 7 +++++-- share/man/man1/brew.1 | 5 ++++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cmd/create.rb b/Library/Homebrew/cmd/create.rb index 791ff23d9f..a7aa78e491 100644 --- a/Library/Homebrew/cmd/create.rb +++ b/Library/Homebrew/cmd/create.rb @@ -1,4 +1,4 @@ -#: * `create` [`--autotools`|`--cmake`] [`--no-fetch`] [`--set-name` ] [`--set-version` ]: +#: * `create` [`--autotools`|`--cmake`] [`--no-fetch`] [`--set-name` ] [`--set-version` ] [`--tap` `/`]: #: Generate a formula for the downloadable file at and open it in the editor. #: Homebrew will attempt to automatically derive the formula name #: and version, but if it fails, you'll have to make your own template. The `wget` @@ -14,6 +14,9 @@ #: #: The options `--set-name` and `--set-version` each take an argument and allow #: you to explicitly set the name and version of the package you are creating. +#: +#: The option `--tap` takes a tap as its argument and generates the formula in +#: the specified tap. require "formula" require "blacklist" @@ -41,10 +44,13 @@ module Homebrew version = ARGV.next if ARGV.include? "--set-version" name = ARGV.next if ARGV.include? "--set-name" + tap = ARGV.next if ARGV.include? "--tap" fc = FormulaCreator.new fc.name = name fc.version = version + fc.tap = Tap.fetch(tap || "homebrew/core") + raise TapUnavailableError, tap unless fc.tap.installed? fc.url = url fc.mode = if ARGV.include? "--cmake" @@ -57,7 +63,7 @@ module Homebrew stem = Pathname.new(url).stem print "Formula name [#{stem}]: " fc.name = __gets || stem - fc.path = Formulary.path(fc.name) + fc.update_path end # Don't allow blacklisted formula, or names that shadow aliases, @@ -91,7 +97,7 @@ end class FormulaCreator attr_reader :url, :sha256 - attr_accessor :name, :version, :path, :mode + attr_accessor :name, :version, :tap, :path, :mode def url=(url) @url = url @@ -107,10 +113,8 @@ class FormulaCreator /(.*?)[-_.]?#{path.version}/.match path.basename @name = $1 end - @path = Formulary.path @name unless @name.nil? - else - @path = Formulary.path name end + update_path if @version @version = Version.new(@version) else @@ -118,6 +122,11 @@ class FormulaCreator end end + def update_path + return if @name.nil? || @tap.nil? + @path = Formulary.path "#{@tap}/#{@name}" + end + def fetch? !head? && !ARGV.include?("--no-fetch") end diff --git a/share/doc/homebrew/brew.1.html b/share/doc/homebrew/brew.1.html index b103c0091d..8489901b83 100644 --- a/share/doc/homebrew/brew.1.html +++ b/share/doc/homebrew/brew.1.html @@ -78,7 +78,7 @@ With --include-aliases, the aliases of internal commands will be in
config

Show Homebrew and system configuration useful for debugging. If you file a bug report, you will likely be asked for this information if you do not provide it.

-
create URL [--autotools|--cmake] [--no-fetch] [--set-name name] [--set-version version]

Generate a formula for the downloadable file at URL and open it in the editor. +

create URL [--autotools|--cmake] [--no-fetch] [--set-name name] [--set-version version] [--tap user/repo]

Generate a formula for the downloadable file at URL and open it in the editor. Homebrew will attempt to automatically derive the formula name and version, but if it fails, you'll have to make your own template. The wget formula serves as a simple example. For the complete API have a look at

@@ -92,7 +92,10 @@ If --cmake is passed, create a basic template for a CMake-style bui will thus not add the SHA256 to the formula for you.

The options --set-name and --set-version each take an argument and allow -you to explicitly set the name and version of the package you are creating.

+you to explicitly set the name and version of the package you are creating.

+ +

The option --tap takes a tap as its argument and generates the formula in +the specified tap.

deps [--1] [-n] [--union] [--installed] [--include-build] [--include-optional] [--skip-recommended] formulae

Show dependencies for formulae. When given multiple formula arguments, show the intersection of dependencies for formulae.

diff --git a/share/man/man1/brew.1 b/share/man/man1/brew.1 index 54f6ca78b0..8aa1144fc5 100644 --- a/share/man/man1/brew.1 +++ b/share/man/man1/brew.1 @@ -110,7 +110,7 @@ If \fB\-\-quiet\fR is passed, list only the names of commands without the header Show Homebrew and system configuration useful for debugging\. If you file a bug report, you will likely be asked for this information if you do not provide it\. . .TP -\fBcreate\fR \fIURL\fR [\fB\-\-autotools\fR|\fB\-\-cmake\fR] [\fB\-\-no\-fetch\fR] [\fB\-\-set\-name\fR \fIname\fR] [\fB\-\-set\-version\fR \fIversion\fR] +\fBcreate\fR \fIURL\fR [\fB\-\-autotools\fR|\fB\-\-cmake\fR] [\fB\-\-no\-fetch\fR] [\fB\-\-set\-name\fR \fIname\fR] [\fB\-\-set\-version\fR \fIversion\fR] [\fB\-\-tap\fR \fIuser\fR\fB/\fR\fIrepo\fR] Generate a formula for the downloadable file at \fIURL\fR and open it in the editor\. Homebrew will attempt to automatically derive the formula name and version, but if it fails, you\'ll have to make your own template\. The \fBwget\fR formula serves as a simple example\. For the complete API have a look at . .IP @@ -125,6 +125,9 @@ If \fB\-\-no\-fetch\fR is passed, Homebrew will not download \fIURL\fR to the ca .IP The options \fB\-\-set\-name\fR and \fB\-\-set\-version\fR each take an argument and allow you to explicitly set the name and version of the package you are creating\. . +.IP +The option \fB\-\-tap\fR takes a tap as its argument and generates the formula in the specified tap\. +. .TP \fBdeps\fR [\fB\-\-1\fR] [\fB\-n\fR] [\fB\-\-union\fR] [\fB\-\-installed\fR] [\fB\-\-include\-build\fR] [\fB\-\-include\-optional\fR] [\fB\-\-skip\-recommended\fR] \fIformulae\fR Show dependencies for \fIformulae\fR\. When given multiple formula arguments, show the intersection of dependencies for \fIformulae\fR\.