#!/usr/bin/env ruby require 'rubygems' Gem.manage_gems require 'rubygems/user_interaction' include Gem::DefaultUserInteraction $gm = Gem::CommandManager.instance class CaptureSay attr_reader :string def initialize @string = '' end def say(msg) @string << msg << "\n" end end def pre(cmd, opts) puts "
" cmd.invoke opts puts "" end def table_of_contents cs = CaptureSay.new use_ui(cs) do $gm['help'].invoke 'commands' end # We're only interested in the lines that actually describe a command. out = cs.string.grep(/^\s+(\w+)\s+(.*)$/).join("\n") # Add a link to the relevant section in the margin. out.gsub(/^\s+(\w+)/) { cmd_name = $1 " [http://rubygems.rubyforge.org/wiki/wiki.pl?GemReference##{cmd_name} -] #{cmd_name}" }.gsub(/RubyGems/, '