2012-08-11 20:22:29 -04:00
|
|
|
class Pry
|
2012-12-25 16:35:17 -05:00
|
|
|
class Command::GemList < Pry::ClassCommand
|
|
|
|
match 'gem-list'
|
2012-08-11 21:26:59 -04:00
|
|
|
group 'Gems'
|
2012-12-25 16:35:17 -05:00
|
|
|
description 'List and search installed gems.'
|
2012-08-11 21:26:59 -04:00
|
|
|
|
2013-01-09 15:23:19 -05:00
|
|
|
banner <<-'BANNER'
|
2012-08-11 20:22:29 -04:00
|
|
|
Usage: gem-list [REGEX]
|
|
|
|
|
2013-01-09 15:23:19 -05:00
|
|
|
List all installed gems, when a regex is provided, limit the output to those
|
|
|
|
that match the regex.
|
2012-08-11 20:22:29 -04:00
|
|
|
BANNER
|
|
|
|
|
2012-12-25 16:35:17 -05:00
|
|
|
def process(pattern = nil)
|
2012-08-11 20:22:29 -04:00
|
|
|
pattern = Regexp.compile(pattern || '')
|
2013-01-08 17:24:53 -05:00
|
|
|
gems = Rubygem.list(pattern).group_by(&:name)
|
2012-08-11 20:22:29 -04: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 16:35:17 -05:00
|
|
|
|
|
|
|
Pry::Commands.add_command(Pry::Command::GemList)
|
2012-08-11 20:22:29 -04:00
|
|
|
end
|