forked from soupmatt/brew-gem
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move rest of guts of brew-gem to lib/brew/gem/cli.rb
- Loading branch information
1 parent
571c275
commit 3cb8945
Showing
3 changed files
with
49 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
require "brew/gem/version" | ||
|
||
module Brew | ||
module Gem | ||
# Your code goes here... | ||
end | ||
end | ||
|
||
require "brew/gem/cli" | ||
require "brew/gem/version" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'erb' | ||
require 'tempfile' | ||
|
||
module Brew::Gem::CLI | ||
HELP_MSG = <<-STR | ||
Please specify a gem name (e.g. brew gem command <name>) | ||
install - Install a brew gem, accepts an optional version argument (e.g. brew gem install <name> <version>) | ||
upgrade - Upgrade to the latest version of a brew gem | ||
uninstall - Uninstall a brew gem | ||
STR | ||
|
||
def self.run(args = ARGV) | ||
if !args[0] || args[0] == 'help' | ||
abort HELP_MSG | ||
end | ||
|
||
command = args[0] | ||
name = args[1] | ||
gems = `gem list --remote "^#{name}$"`.lines | ||
|
||
unless gems.detect { |f| f =~ /^#{name} \(([^\s,]+).*\)/ } | ||
abort "Could not find a valid gem '#{name}'" | ||
end | ||
|
||
version = args[2] || $1 | ||
|
||
klass = 'Gem' + name.capitalize.gsub(/[-_.\s]([a-zA-Z0-9])/) { $1.upcase }.gsub('+', 'x') | ||
user_gemrc = "#{ENV['HOME']}/.gemrc" | ||
template_file = File.expand_path('../template.rb.erb', __FILE__) | ||
template = ERB.new(File.read(template_file)) | ||
filename = File.join Dir.tmpdir, "gem-#{name}.rb" | ||
|
||
begin | ||
open(filename, 'w') do |f| | ||
f.puts template.result(binding) | ||
end | ||
|
||
system "brew #{command} #{filename}" | ||
ensure | ||
File.unlink filename | ||
end | ||
end | ||
end |
3cb8945
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3cb8945