gem-toolbox 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +3 -0
- data/README.rdoc +63 -0
- data/lib/gem_toolbox/common_options.rb +72 -0
- data/lib/rubygems/commands/doc_command.rb +60 -0
- data/lib/rubygems/commands/history_command.rb +46 -0
- data/lib/rubygems/commands/open_command.rb +45 -0
- data/lib/rubygems/commands/readme_command.rb +42 -0
- data/lib/rubygems/commands/visit_command.rb +36 -0
- data/lib/rubygems_plugin.rb +13 -0
- metadata +73 -0
data/CHANGES.md
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
= Gem-Toolbox
|
2
|
+
|
3
|
+
This is a gem that adds a few extra commands to RubyGem: *open*, *readme*, *history* and *doc* and *visit*.
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
|
8
|
+
=== Opening a gem
|
9
|
+
|
10
|
+
To open a gem's installation folder in textmate:
|
11
|
+
|
12
|
+
$ export EDITOR=mate
|
13
|
+
$ gem open gem-toolbox
|
14
|
+
|
15
|
+
Note: This is the same command as the one in open_gem.
|
16
|
+
|
17
|
+
|
18
|
+
=== Displaying the README
|
19
|
+
|
20
|
+
The readme command will try to find a readme file and
|
21
|
+
display it using $GEM_PAGER or $PAGER:
|
22
|
+
|
23
|
+
$ export PAGER=less
|
24
|
+
$ gem readme gem-toolbox
|
25
|
+
|
26
|
+
If you prefer to read it using a editor:
|
27
|
+
|
28
|
+
$ gem readme gem-toolbox -c vim
|
29
|
+
|
30
|
+
|
31
|
+
=== Viewing the gem's changelog
|
32
|
+
|
33
|
+
You can view the changelog using the *history* command:
|
34
|
+
|
35
|
+
$ gem history gem-toolbox
|
36
|
+
|
37
|
+
It will search the gem for a typical changelog file (history, changes, changelog)
|
38
|
+
and display it using $GEM_PAGER or $PAGER or a custom command (-c).
|
39
|
+
|
40
|
+
|
41
|
+
=== Browsing the documentation
|
42
|
+
|
43
|
+
To browse the documentation for a gem in your browser:
|
44
|
+
|
45
|
+
$ gem doc gem-toolbox
|
46
|
+
|
47
|
+
You can use a custom command too:
|
48
|
+
|
49
|
+
$ gem doc gem-toolbox -c lynx
|
50
|
+
|
51
|
+
Note: This is the same command as *read* from open_gem.
|
52
|
+
|
53
|
+
|
54
|
+
=== Visiting the gem's homepage
|
55
|
+
|
56
|
+
This opens the gem's homepage in your favorite browser
|
57
|
+
|
58
|
+
$ gem visit gem-toolbox
|
59
|
+
|
60
|
+
|
61
|
+
== Credits
|
62
|
+
|
63
|
+
This gem is based on adamsanderson's open_gem, thank you!
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module GemToolbox
|
3
|
+
|
4
|
+
# This module was ripped from open_gem
|
5
|
+
module CommonOptions
|
6
|
+
|
7
|
+
def add_command_option(description=nil)
|
8
|
+
add_option('-c', '--command COMMAND', description || 'Execute command at path of the gem') { |value,options| options[:command] = value }
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_latest_version_option
|
12
|
+
add_option('-l', '--latest', 'If there are multiple versions, use the latest') { |value,options| options[:latest] = true }
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_exact_match_option
|
16
|
+
add_option('-x', '--exact', 'Only list exact matches') { |value,options| options[:exact] = true }
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_spec(name)
|
20
|
+
dep = Gem::Dependency.new(name, options[:version])
|
21
|
+
specs = Gem.source_index.search(dep)
|
22
|
+
if block_given?
|
23
|
+
specs = specs.select{|spec| yield spec}
|
24
|
+
end
|
25
|
+
|
26
|
+
if specs.length == 0
|
27
|
+
# If we have not tried to do a pattern match yet, fall back on it.
|
28
|
+
if(!options[:exact] && !name.is_a?(Regexp))
|
29
|
+
pattern = /#{Regexp.escape name}/
|
30
|
+
get_spec(pattern)
|
31
|
+
else
|
32
|
+
say "#{name.inspect} is not available"
|
33
|
+
return nil
|
34
|
+
end
|
35
|
+
|
36
|
+
elsif specs.length == 1 || options[:latest]
|
37
|
+
return specs.last
|
38
|
+
|
39
|
+
else
|
40
|
+
choices = specs.map{|s|"#{s.name} #{s.version}"}
|
41
|
+
c,i = choose_from_list "Open which gem?", choices
|
42
|
+
return specs[i] if i
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_path(name)
|
48
|
+
if spec = get_spec(name)
|
49
|
+
spec.full_gem_path
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def show(file)
|
54
|
+
pager = options[:command] || ENV['GEM_PAGER'] || ENV['PAGER']
|
55
|
+
|
56
|
+
if !pager
|
57
|
+
say "Either set $GEM_PAGER, $PAGER, or use -c <command_name>"
|
58
|
+
else
|
59
|
+
command_parts = Shellwords.shellwords(pager)
|
60
|
+
command_parts << file
|
61
|
+
success = system(*command_parts)
|
62
|
+
if !success
|
63
|
+
raise Gem::CommandLineError, "Could not run '#{pager} #{file}', exit code: #{$?.exitstatus}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'launchy'
|
3
|
+
|
4
|
+
# DocCommand will open a gem's rdoc
|
5
|
+
# This command is the same as the open_gem ReadCommand
|
6
|
+
class Gem::Commands::DocCommand < Gem::Command
|
7
|
+
include GemToolbox::CommonOptions
|
8
|
+
include Gem::VersionOption
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
super 'doc', "Read the gem's documentation",
|
12
|
+
:command => nil,
|
13
|
+
:version=> Gem::Requirement.default,
|
14
|
+
:latest=> false
|
15
|
+
|
16
|
+
add_command_option "Application to read rdoc with"
|
17
|
+
add_latest_version_option
|
18
|
+
add_version_option
|
19
|
+
add_exact_match_option
|
20
|
+
end
|
21
|
+
|
22
|
+
def arguments # :nodoc:
|
23
|
+
"GEMNAME gem to read"
|
24
|
+
end
|
25
|
+
|
26
|
+
def execute
|
27
|
+
name = get_one_gem_name
|
28
|
+
spec = get_spec(name){|s| s.has_rdoc? }
|
29
|
+
if spec && path = get_path(spec)
|
30
|
+
if File.exists? path
|
31
|
+
read_gem path
|
32
|
+
elsif ask_yes_no "The rdoc seems to be missing, would you like to generate one?", true
|
33
|
+
generate_rdoc spec
|
34
|
+
read_gem path
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_path(spec)
|
40
|
+
File.join(spec.installation_path, "doc", spec.full_name, 'rdoc','index.html')
|
41
|
+
end
|
42
|
+
|
43
|
+
def generate_rdoc(spec)
|
44
|
+
Gem::DocManager.new(spec).generate_rdoc
|
45
|
+
end
|
46
|
+
|
47
|
+
def read_gem(path)
|
48
|
+
if options[:command]
|
49
|
+
command_parts = Shellwords.shellwords(options[:command])
|
50
|
+
command_parts << path
|
51
|
+
success = system(*command_parts)
|
52
|
+
if !success
|
53
|
+
raise Gem::CommandLineError, "Could not run '#{options[:command]} #{path}', exit code: #{$?.exitstatus}"
|
54
|
+
end
|
55
|
+
else
|
56
|
+
Launchy::Browser.run("file://"+path)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# HistoryCommand displays the gem's changelog using $GEM_PAGER or $PAGER
|
4
|
+
class Gem::Commands::HistoryCommand < Gem::Command
|
5
|
+
include GemToolbox::CommonOptions
|
6
|
+
include Gem::VersionOption
|
7
|
+
|
8
|
+
CHANGELOG_PATTERN = /^(history|changelog|changes)/i
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
super "history", "Show gem's changelog using $GEM_PAGER or $PAGER",
|
12
|
+
:command => nil,
|
13
|
+
:version => Gem::Requirement.default,
|
14
|
+
:latest => false
|
15
|
+
|
16
|
+
add_latest_version_option
|
17
|
+
add_exact_match_option
|
18
|
+
add_version_option
|
19
|
+
add_command_option
|
20
|
+
end
|
21
|
+
|
22
|
+
def arguments # :nodoc:
|
23
|
+
"GEMNAME Gem to show changelog for"
|
24
|
+
end
|
25
|
+
|
26
|
+
def execute
|
27
|
+
name = get_one_optional_argument
|
28
|
+
path = get_path(name)
|
29
|
+
|
30
|
+
if path
|
31
|
+
if log = find_changelog(path)
|
32
|
+
show log
|
33
|
+
else
|
34
|
+
say "No changelog found for #{name}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_changelog(path)
|
40
|
+
Dir.glob(File.join(path, "*")).each do |file|
|
41
|
+
return file if File.file?(file) && File.basename(file) =~ CHANGELOG_PATTERN
|
42
|
+
end
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# OpenCommand will open a gem's source path
|
4
|
+
# This command is the same as +open+ in open_gem
|
5
|
+
class Gem::Commands::OpenCommand < Gem::Command
|
6
|
+
include GemToolbox::CommonOptions
|
7
|
+
include Gem::VersionOption
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super 'open', "Opens the gem's source directory with $GEM_OPEN_EDITOR or $EDITOR",
|
11
|
+
:command => nil,
|
12
|
+
:version=> Gem::Requirement.default,
|
13
|
+
:latest=> false
|
14
|
+
|
15
|
+
add_command_option
|
16
|
+
add_latest_version_option
|
17
|
+
add_version_option
|
18
|
+
add_exact_match_option
|
19
|
+
end
|
20
|
+
|
21
|
+
def arguments # :nodoc:
|
22
|
+
"GEMNAME gem to open"
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute
|
26
|
+
name = get_one_gem_name
|
27
|
+
path = get_path(name)
|
28
|
+
|
29
|
+
open_gem(path) if path
|
30
|
+
end
|
31
|
+
|
32
|
+
def open_gem(path)
|
33
|
+
editor = options[:command] || ENV['GEM_OPEN_EDITOR'] || ENV['VISUAL'] || ENV['EDITOR']
|
34
|
+
if !editor
|
35
|
+
say "Either set $GEM_OPEN_EDITOR, $VISUAL, $EDITOR, or use -c <command_name>"
|
36
|
+
else
|
37
|
+
command_parts = Shellwords.shellwords(editor)
|
38
|
+
command_parts << path
|
39
|
+
success = system(*command_parts)
|
40
|
+
if !success
|
41
|
+
raise Gem::CommandLineError, "Could not run '#{editor} #{path}', exit code: #{$?.exitstatus}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# ReadmeCommand opens the gem's readme file using $PAGER or $GEM_PAGER
|
4
|
+
class Gem::Commands::ReadmeCommand < Gem::Command
|
5
|
+
include GemToolbox::CommonOptions
|
6
|
+
include Gem::VersionOption
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super "readme", "Show gem's readme file using $GEM_PAGER or $PAGER",
|
10
|
+
:command => nil,
|
11
|
+
:version => Gem::Requirement.default,
|
12
|
+
:latest => false
|
13
|
+
|
14
|
+
add_latest_version_option
|
15
|
+
add_exact_match_option
|
16
|
+
add_version_option
|
17
|
+
add_command_option
|
18
|
+
end
|
19
|
+
|
20
|
+
def arguments # :nodoc:
|
21
|
+
"GEMNAME Gem to show readme for"
|
22
|
+
end
|
23
|
+
|
24
|
+
def execute
|
25
|
+
name = get_one_optional_argument
|
26
|
+
path = get_path(name)
|
27
|
+
|
28
|
+
if path
|
29
|
+
if file = find_readme(path)
|
30
|
+
show file
|
31
|
+
else
|
32
|
+
say "No readme found for #{name}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def find_readme(path)
|
38
|
+
Dir.glob(File.join(path, "{README,readme,Readme,ReadMe}*")).first
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'launchy'
|
4
|
+
# VisitCommand opens the gem's homepage in a browser
|
5
|
+
class Gem::Commands::VisitCommand < Gem::Command
|
6
|
+
include GemToolbox::CommonOptions
|
7
|
+
include Gem::VersionOption
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super "readme", "Visit gem's homepage in a browser",
|
11
|
+
:command => nil,
|
12
|
+
:version => Gem::Requirement.default,
|
13
|
+
:latest => false
|
14
|
+
|
15
|
+
add_latest_version_option
|
16
|
+
add_exact_match_option
|
17
|
+
add_version_option
|
18
|
+
end
|
19
|
+
|
20
|
+
def arguments # :nodoc:
|
21
|
+
"GEMNAME Gem to visit"
|
22
|
+
end
|
23
|
+
|
24
|
+
def execute
|
25
|
+
name = get_one_gem_name
|
26
|
+
spec = get_spec(name)
|
27
|
+
|
28
|
+
if spec.homepage
|
29
|
+
Launchy::Browser.run(spec.homepage)
|
30
|
+
else
|
31
|
+
say "Homepage not defined for #{name}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems/command_manager'
|
3
|
+
require 'rubygems/command'
|
4
|
+
require 'rubygems/dependency'
|
5
|
+
require 'rubygems/version_option'
|
6
|
+
require 'shellwords'
|
7
|
+
require 'gem_toolbox/common_options'
|
8
|
+
|
9
|
+
Gem::CommandManager.instance.register_command :open
|
10
|
+
Gem::CommandManager.instance.register_command :doc
|
11
|
+
Gem::CommandManager.instance.register_command :history
|
12
|
+
Gem::CommandManager.instance.register_command :readme
|
13
|
+
Gem::CommandManager.instance.register_command :visit
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem-toolbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Gudleik Rasch
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-09-13 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: "Gem-Toolbox is a RubyGems plugin that adds extra commands to RubyGems: open, doc, history, readme and visit"
|
22
|
+
email:
|
23
|
+
- gudleik@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.rdoc
|
30
|
+
files:
|
31
|
+
- lib/gem_toolbox/common_options.rb
|
32
|
+
- lib/rubygems/commands/doc_command.rb
|
33
|
+
- lib/rubygems/commands/history_command.rb
|
34
|
+
- lib/rubygems/commands/open_command.rb
|
35
|
+
- lib/rubygems/commands/readme_command.rb
|
36
|
+
- lib/rubygems/commands/visit_command.rb
|
37
|
+
- lib/rubygems_plugin.rb
|
38
|
+
- README.rdoc
|
39
|
+
- CHANGES.md
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/gudleik/gem-toolbox
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --charset=UTF-8
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.7
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: "Adds extra commands to RubyGems: open, doc, history, readme and visit"
|
72
|
+
test_files: []
|
73
|
+
|