lib/rubygems/commands/open_command.rb in open_gem-1.2.0 vs lib/rubygems/commands/open_command.rb in open_gem-1.3.0
- old
+ new
@@ -1,31 +1,18 @@
-require 'shellwords'
-
-require 'rubygems/command'
-require 'rubygems/dependency'
-require 'rubygems/version_option'
-
# OpenCommand will open a gem's source path
class Gem::Commands::OpenCommand < Gem::Command
+ include OpenGem::CommonOptions
include Gem::VersionOption
def initialize
super 'open', "Opens the gem's source directory with $GEM_OPEN_EDITOR or $EDITOR",
:command => nil,
:version=> Gem::Requirement.default,
:latest=> false
- add_option('-c', '--command COMMAND',
- 'Execute command at path of the rubygem') do |value, options|
- options[:command] = value
- end
-
- add_option('-l', '--latest',
- 'If there are multiple versions, open the latest') do |value, options|
- options[:latest] = true
- end
-
+ add_command_option
+ add_latest_version_option
add_version_option
end
def arguments # :nodoc:
"GEMNAME gem to open"
@@ -37,24 +24,11 @@
open_gem(path) if path
end
def get_path(name)
- dep = Gem::Dependency.new name, options[:version]
- specs = Gem.source_index.search dep
-
- if specs.length == 0
- say "Could not find '#{name}'"
- return nil
-
- elsif specs.length == 1 || options[:latest]
- return specs.last.full_gem_path
-
- else
- choices = specs.map{|s|"#{s.name} #{s.version}"}
- c,i = choose_from_list "Open which gem?", choices
- return specs[i].full_gem_path if i
-
+ if spec = get_spec(name)
+ spec.full_gem_path
end
end
def open_gem(path)
editor = options[:command] || ENV['GEM_OPEN_EDITOR'] || ENV['EDITOR']
\ No newline at end of file