gemedit 0.0.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,11 @@
1
+ == 0.9.0 2009-11-15
2
+
3
+ * 1 major change:
4
+ * installs itself as a rubygems command, use "gem edit" to run
5
+ * 2 minor changes
6
+ * verbose short switch becomes -V instead of -v
7
+ * -p/--pretend are rename to -d/--dry-run to be consistent with other gem commands
8
+
1
9
  == 0.0.2 2008-03-07
2
10
 
3
11
  * 1 minor enhancement:
data/README.txt CHANGED
@@ -14,21 +14,17 @@ Gemedit can be installed via RubyGems:
14
14
 
15
15
  $ sudo gem install gemedit
16
16
 
17
- If you would like some basic command completion for installed gems add the following to your ~/.bashrc or ~/.profile:
18
-
19
- complete -C "/usr/bin/gemedit --complete" gemedit
20
-
21
17
  == USAGE:
22
18
 
23
19
  If you want to see how gemedit works just install it and run this:
24
- $ gemedit gemedit
20
+ $ gem edit gemedit
25
21
 
26
- Gemedit tries to use your favorite editor from your <tt>$VISUAL</tt> or <tt>$EDITOR</tt> environment variable. It will fall back to <em>everyone's</em> favorite editor: *vi*. You can specify the editor with the <tt>-e/--editor</tt> switch. Run this to view the source for +rake+ in TextMate[http://macromates.com]:
27
- $ gemedit -e mate rake
22
+ Gemedit tries to use your favorite editor from your <tt>$GEMEDITOR</tt>, <tt>$VISUAL</tt> or <tt>$EDITOR</tt> environment variable. It will fall back to <em>everyone's</em> favorite editor: *vi*. You can specify the editor with the <tt>-e/--editor</tt> switch. Run this to view the source for +rake+ in TextMate[http://macromates.com]:
23
+ $ gem edit -e mate rake
28
24
 
29
25
  And of course, help is available:
30
- $ gemedit -h
31
- $ gemedit --help
26
+ $ gem edit -h
27
+ $ gem edit --help
32
28
 
33
29
  == DOCUMENTATION:
34
30
 
@@ -3,88 +3,6 @@
3
3
  # Created on 2008-2-27.
4
4
  # Copyright (c) 2008. All rights reserved.
5
5
 
6
- begin
7
- require 'rubygems'
8
- rescue LoadError
9
- # no rubygems to load, so we fail silently
10
- end
6
+ $stderr.puts 'gemedit is now a gem command, see gem edit --help'
11
7
 
12
- require 'optparse'
13
-
14
- OPTIONS = {
15
- :verbose => false,
16
- :pretend => false,
17
- :editor => ENV['VISUAL'] || ENV['EDITOR'] || 'vi'
18
- }
19
-
20
- parser = OptionParser.new do |opts|
21
- opts.banner = <<BANNER
22
- Open the source of installed gems in your favorite editor
23
-
24
- Usage: #{File.basename($0)} GEM_NAME...
25
-
26
- Options are:
27
- BANNER
28
- opts.on("-e", "--editor=EDITOR", String,
29
- "The editor to open the gems with", "Default: #{OPTIONS[:editor]}") { |editor| OPTIONS[:editor] = editor }
30
- opts.on("-p", "--pretend",
31
- "Shows what command would be run without running it", "Turns on verbose logging", "Default: #{OPTIONS[:pretend]}") { |pretend|
32
- OPTIONS[:pretend] = OPTIONS[:verbose] = true
33
- }
34
- opts.on("-v", "--verbose",
35
- "Enable verbose logging", "Default: #{OPTIONS[:verbose]}") { |verbose| OPTIONS[:verbose] = true }
36
- opts.on("-h", "--help",
37
- "Show this help message.") { puts opts; exit }
38
- end
39
-
40
- if ARGV.include?('--complete')
41
- exit 0 unless /\b#{Regexp.escape(File.basename($0))}\b/ =~ ENV["COMP_LINE"]
42
- after_match = $'
43
- complete_term = (after_match.empty? || after_match =~ /\s$/) ? nil : after_match.split.last
44
- completions = if complete_term =~ /\A-/
45
- parser.top.list.select { |opt| OptionParser::Switch === opt }.inject([]) { |ary, opt|
46
- ary + opt.short + opt.long
47
- }.select { |opt_string| opt_string =~ /\A#{Regexp.escape(complete_term)}/ }
48
- elsif complete_term
49
- Gem.source_index.inject([]) { |ary, (full_name, spec)| ary << full_name if /^#{Regexp.escape(complete_term)}/i =~ full_name; ary }
50
- else
51
- Gem.source_index.map { |full_name, spec| full_name }
52
- end
53
- puts completions
54
- exit 0
55
- end
56
-
57
- parser.parse!(ARGV)
58
-
59
- def get_gem(gem_name)
60
- possible_gems = Gem.source_index.inject([]) { |ary, (name, spec)| ary << spec if /^#{Regexp.escape(gem_name)}/i =~ spec.full_name; ary }.sort_by { |gem| gem.version }.reverse
61
- if possible_gems.size < 1
62
- puts "No gems found for #{gem_name}... skipping"
63
- end
64
- gem = possible_gems.first if possible_gems.map { |g| g.name }.uniq.size == 1
65
- gem ||= begin
66
- require 'rubygems/user_interaction'
67
- include Gem::DefaultUserInteraction
68
- list = possible_gems.map { |g| "#{g.name} #{g.version}" }
69
- list << 'None of the above'
70
- name, index = ui.choose_from_list("Choose which gem to view for '#{gem_name}':", list)
71
- possible_gems[index] if (0...possible_gems.size).include?(index)
72
- end
73
- gem
74
- end
75
-
76
- gems = ARGV.reject { |arg| arg.empty? }.map { |gem_name| get_gem(gem_name) }.compact
77
-
78
- if gems.size > 0
79
- puts "Opening the following gems with #{OPTIONS[:editor]}:" if OPTIONS[:verbose]
80
- paths = gems.map do |gem|
81
- puts " #{gem.full_name}: #{gem.full_gem_path}" if OPTIONS[:verbose]
82
- %Q{"#{gem.full_gem_path}"}
83
- end
84
- cmd = "#{OPTIONS[:editor]} #{paths.join(' ')}"
85
- puts "Running `#{cmd}`" if OPTIONS[:verbose]
86
- exec cmd unless OPTIONS[:pretend]
87
- else
88
- puts "No gems found for editing"
89
- end
90
- exit 0
8
+ exit 1
@@ -1,5 +1,6 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
+ require 'gemedit/edit_command'
2
3
 
3
4
  module Gemedit
4
5
 
5
- end
6
+ end
@@ -0,0 +1,74 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/version_option'
3
+
4
+ class Gem::Commands::EditCommand < Gem::Command
5
+
6
+ OPTIONS = {
7
+ :version => Gem::Requirement.default,
8
+ :verbose => false,
9
+ :dryrun => false,
10
+ :editor => ENV['GEMEDITOR'] || ENV['VISUAL'] || ENV['EDITOR'] || 'vi'
11
+ }
12
+
13
+ include Gem::VersionOption
14
+
15
+ def initialize
16
+ super 'edit', 'Open an installed gem in your favorite editor', OPTIONS
17
+
18
+ add_version_option
19
+
20
+ add_option('-e', '--editor EDITOR', String,
21
+ 'The editor to use to open the gems',
22
+ 'GEMEDITOR, VISUAL and EDITOR environment variables',
23
+ 'are used to find the default',
24
+ "Default: #{OPTIONS[:editor]}") do |editor, options|
25
+ options[:editor] = editor
26
+ end
27
+
28
+ add_option('-d', '--[no-]dry-run',
29
+ 'Shows what command would be run without running it',
30
+ 'Turns on verbose logging', "Default: #{OPTIONS[:dryrun]}") do |dryrun, options|
31
+ Gem.configuration.verbose ||= true if dryrun
32
+ options[:dryrun] = dryrun
33
+ end
34
+ end
35
+
36
+ def arguments # :nodoc:
37
+ "GEMNAME name of gem to open in your favorite editor"
38
+ end
39
+
40
+ def defaults_str # :nodoc:
41
+ "--version '#{OPTIONS[:version]}' --editor #{OPTIONS[:editor]} --no-dry-run"
42
+ end
43
+
44
+ def usage # :nodoc:
45
+ "#{program_name} [options] GEMNAME [GEMNAME ...]"
46
+ end
47
+
48
+ def execute
49
+ version = options[:version] || OPTIONS[:version]
50
+
51
+ gem_specs = get_all_gem_names.map { |gem_name|
52
+ if spec = Gem.source_index.find_name(gem_name, version).last
53
+ say "Found gem for '#{gem_name}' with version #{version}" if Gem.configuration.verbose
54
+ else
55
+ say "No gem found for '#{gem_name}' with version #{version}" if Gem.configuration.verbose
56
+ end
57
+ spec
58
+ }.compact
59
+
60
+ if gem_specs.size > 0
61
+ say "Opening the following gems with #{options[:editor]}:" if Gem.configuration.verbose
62
+ paths = gem_specs.map do |spec|
63
+ say " #{spec.full_name} #{spec.full_gem_path}" if Gem.configuration.verbose
64
+ %Q{"#{spec.full_gem_path}"}
65
+ end
66
+ cmd = "#{options[:editor]} #{paths.join(' ')}"
67
+ say "Running `#{cmd}`" if Gem.configuration.verbose
68
+ exec cmd unless options[:dryrun]
69
+ else
70
+ say "No gems found for #{get_all_gem_names.join(', ')}"
71
+ raise Gem::SystemExitException, 1
72
+ end
73
+ end
74
+ end
@@ -1,8 +1,8 @@
1
1
  module Gemedit #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 0
5
- TINY = 2
4
+ MINOR = 9
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,4 @@
1
+ require 'rubygems/command_manager'
2
+
3
+ require 'gemedit'
4
+ Gem::CommandManager.instance.register_command :edit
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemedit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Marlow
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-07 00:00:00 -07:00
12
+ date: 2009-11-15 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.0
24
+ version:
16
25
  description: A utility to view a gem's source in your favorite editor
17
26
  email:
18
27
  - lmarlow@rubyforge.org
@@ -29,10 +38,14 @@ files:
29
38
  - License.txt
30
39
  - README.txt
31
40
  - bin/gemedit
41
+ - lib/rubygems_plugin.rb
32
42
  - lib/gemedit.rb
33
43
  - lib/gemedit/version.rb
44
+ - lib/gemedit/edit_command.rb
34
45
  has_rdoc: true
35
46
  homepage: http://gemedit.rubyforge.org
47
+ licenses: []
48
+
36
49
  post_install_message:
37
50
  rdoc_options:
38
51
  - --main
@@ -54,9 +67,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
67
  requirements: []
55
68
 
56
69
  rubyforge_project: gemedit
57
- rubygems_version: 1.0.1
70
+ rubygems_version: 1.3.5
58
71
  signing_key:
59
- specification_version: 2
72
+ specification_version: 3
60
73
  summary: A utility to view a gem's source in your favorite editor
61
74
  test_files: []
62
75