Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add open command to rvm

  • Loading branch information...
commit d6701ad227cfdf2f1b9459e813ad0e96a29bfc52 1 parent 47763a1
Vitali Fokin quozd authored
77 lib/rubygems/commands/open_command.rb
View
@@ -0,0 +1,77 @@
+require 'English'
+require 'rubygems/command'
+require 'rubygems/version_option'
+require 'rubygems/util'
+
+class Gem::Commands::OpenCommand < Gem::Command
+
+ include Gem::VersionOption
+
+ def initialize
+ super 'open', 'Open gem sources in editor'
+
+ add_option('-e', '--editor EDITOR', String,
+ "Opens gem sources in EDITOR") do |editor, options|
+ options[:editor] = editor ||
+ ENV['GEM_EDITOR'] ||
+ ENV['VISUAL'] ||
+ ENV['EDITOR'] ||
+ 'vi'
+ end
+ end
+
+ def arguments # :nodoc:
+ "GEMNAME name of gem to open in editor"
+ end
+
+ def defaults_str # :nodoc:
+ "-e $EDITOR"
+ end
+
+ def description # :nodoc:
+ <<-EOF
+ The open command opens gem in editor and changes current path
+ to gem's source directory. Editor can be specified, otherwise
+ $EDITOR would be invoked.
+ EOF
+ end
+
+ def usage # :nodoc:
+ "#{program_name} GEMNAME [-e EDITOR]"
+ end
+
+ def execute
+ @version = options[:version] || Gem::Requirement.default
+ @editor = options[:editor]
+
+ found = open_gem(get_one_gem_name)
+
+ terminate_interaction 1 unless found
+ end
+
+ def open_gem name
+ spec = spec_for name
+ return false unless spec
+
+ open_editor(spec.full_gem_path)
+ end
+
+ def open_editor path
+ Dir.chdir(path) do
+ pid = spawn(@editor, path)
+ Process.detach(pid)
+ end
+ #unless Gem::Util.silent_system(@editor, path)
+ # say "Unable to open #{@editor}"
+ # terminate_interaction 1
+ #end
+ end
+
+ def spec_for name
+ spec = Gem::Specification.find_all_by_name(name, @version).last
+
+ return spec if spec
+
+ say "Unable to find gem '#{name}'"
+ end
+end
34 test/rubygems/test_gem_commands_open_command.rb
View
@@ -0,0 +1,34 @@
+require 'rubygems/test_case'
+require 'rubygems/commands/open_command'
+
+class TestGemCommandsOpenCommand < Gem::TestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::OpenCommand.new
+ end
+
+ def gem name
+ spec = quick_gem name do |gem|
+ gem.files = %W[lib/#{name}.rb Rakefile]
+ end
+ write_file File.join(*%W[gems #{spec.full_name} lib #{name}.rb])
+ write_file File.join(*%W[gems #{spec.full_name} Rakefile])
+ end
+
+ def test_execute
+ @cmd.options[:editor] = 'notepad'
+ @cmd.options[:args] = %w[foo]
+
+ gem 'foo'
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "", @ui.error
+ end
+
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.