lib/brew/gem/cli.rb in brew-gem-0.8.1 vs lib/brew/gem/cli.rb in brew-gem-0.8.2
- old
+ new
@@ -8,10 +8,11 @@
"install" => ("Install a brew gem, accepts an optional version argument\n" +
" (e.g. brew gem install <name> [version])"),
"upgrade" => "Upgrade to the latest version of a brew gem",
"uninstall" => "Uninstall a brew gem",
"info" => "Show information for an installed gem",
+ "formula" => "Print out the generated formula for a gem",
"help" => "This message"
}
def help_msg
(["Please specify a gem name (e.g. brew gem command <name>)"] +
@@ -40,14 +41,15 @@
args[0..3]
end
def expand_formula(name, version, use_homebrew_ruby=false)
- klass = 'Gem' + name.capitalize.gsub(/[-_.\s]([a-zA-Z0-9])/) { $1.upcase }.gsub('+', 'x')
- user_gemrc = "#{ENV['HOME']}/.gemrc"
- template_file = File.expand_path('../formula.rb.erb', __FILE__)
- template = ERB.new(File.read(template_file))
+ klass = 'Gem' + name.capitalize.gsub(/[-_.\s]([a-zA-Z0-9])/) { $1.upcase }.gsub('+', 'x')
+ user_gemrc = "#{ENV['HOME']}/.gemrc"
+ homebrew_prefix = ENV['HOMEBREW_PREFIX'] || `brew --prefix`.chomp
+ template_file = File.expand_path('../formula.rb.erb', __FILE__)
+ template = ERB.new(File.read(template_file))
template.result(binding)
end
def with_temp_formula(name, version, use_homebrew_ruby)
filename = File.join Dir.tmpdir, "gem-#{name}.rb"
@@ -72,10 +74,15 @@
use_homebrew_ruby = homebrew_ruby == homebrew_ruby_flag
version = fetch_version(name, supplied_version)
with_temp_formula(name, version, use_homebrew_ruby) do |filename|
- system "brew #{command} #{filename}"
- exit $?.exitstatus unless $?.success?
+ case command
+ when "formula"
+ $stdout.puts File.read(filename)
+ else
+ system "brew #{command} #{filename}"
+ exit $?.exitstatus unless $?.success?
+ end
end
end
end