Hi,
Puppet (http://reductivelabs.com/trac/puppet) uses the `gem list' command as
part of its gem package provider. I'm thinking about fixing the provider to
use the RubyGems API instead of the command line tool as the command line tool
produces output that isn't strictly related to the local or remote gem list,
and incurs extra output parsing.
E.g for the local gem list case query_command.rb uses
Gem.source_index.search(name) to get a list of local gems. When calling it I
still see output related to updating the gem index. I'd like to avoid this
extra output; is that possible?
Also: the attached patch against 1.1.0 refactors output_query_results into two
methods, one that produces the list of gems with their versions and another
that outputs this list in the same format output_query_results does today.
This makes it easier to programmatically access the list of local and remote
gems.
In case I'm reinventing the wheel, please tell me so.
--
Jos Backus
jos at catnook.com
diff --git a/commands/query_command.rb b/commands/query_command.rb
index df17cc8..7ffe59e 100644
--- a/commands/query_command.rb
+++ b/commands/query_command.rb
@@ -102,7 +102,7 @@ class Gem::Commands::QueryCommand < Gem::Command
!Gem.source_index.search(dep).empty?
end
- def output_query_results(gemspecs)
+ def collect_query_results(gemspecs)
output = []
gem_list_with_version = {}
@@ -128,18 +128,37 @@ class Gem::Commands::QueryCommand < Gem::Command
end
end
- entry = gem_name.dup
+ entry = {}
+ entry[:name] = gem_name.dup
if options[:versions] then
versions = list_of_matching.map { |s| s.version }.uniq
- entry << " (#{versions.join ', '})"
+ entry[:versions] ||= []
+ entry[:versions] += versions
end
- entry << "\n" << format_text(list_of_matching[0].summary, 68, 4) if
- options[:details]
+ entry[:details] = list_of_matching[0].summary if options[:details]
output << entry
end
+ output
+ end
+
+ def output_query_results(gemspecs)
+ output = []
+ collect_query_results(gemspecs).each do |entry|
+ text = entry[:name]
+
+ if options[:versions] then
+ versions = entry[:versions]
+ text << " (#{versions.join ', '})"
+ end
+
+ text << "\n" << format_text(entry[:details], 68, 4) if
+ options[:details]
+ output << text
+ end
+
say output.join(options[:details] ? "\n\n" : "\n")
end
_______________________________________________
Rubygems-developers mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rubygems-developers