2012-08-12 00:22:29 +00:00
|
|
|
class Pry
|
2012-12-25 21:35:17 +00:00
|
|
|
class Command::GemList < Pry::ClassCommand
|
|
|
|
match 'gem-list'
|
2012-08-12 01:26:59 +00:00
|
|
|
group 'Gems'
|
2012-12-25 21:35:17 +00:00
|
|
|
description 'List and search installed gems.'
|
2012-08-12 01:26:59 +00:00
|
|
|
|
2012-08-12 00:22:29 +00:00
|
|
|
banner <<-BANNER
|
|
|
|
Usage: gem-list [REGEX]
|
|
|
|
|
|
|
|
List all installed gems, when a regex is provided, limit the output to those that
|
|
|
|
match the regex.
|
|
|
|
BANNER
|
|
|
|
|
2012-12-25 21:35:17 +00:00
|
|
|
def process(pattern = nil)
|
2012-08-12 00:22:29 +00:00
|
|
|
pattern = Regexp.compile(pattern || '')
|
2013-01-08 22:24:53 +00:00
|
|
|
gems = Rubygem.list(pattern).group_by(&:name)
|
2012-08-12 00:22:29 +00:00
|
|
|
|
|
|
|
gems.each do |gem, specs|
|
|
|
|
specs.sort! do |a,b|
|
|
|
|
Gem::Version.new(b.version) <=> Gem::Version.new(a.version)
|
|
|
|
end
|
|
|
|
|
|
|
|
versions = specs.each_with_index.map do |spec, index|
|
|
|
|
index == 0 ? text.bright_green(spec.version.to_s) : text.green(spec.version.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
output.puts "#{text.default gem} (#{versions.join ', '})"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-12-25 21:35:17 +00:00
|
|
|
|
|
|
|
Pry::Commands.add_command(Pry::Command::GemList)
|
2012-08-12 00:22:29 +00:00
|
|
|
end
|