Sha256: 27c912517d55dbc86275f542af7497dab510f2403559d5690fdca91a3d6adeda

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

#!/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 "<pre>"
  cmd.invoke opts
  puts "</pre>"
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/, '<nowiki>RubyGems</nowiki>')
end

while line = gets
  if line =~ /^!/
    cmd, arg = line.split
    case cmd
    when "!usage"
      begin
	cmdobj = $gm[arg]
	pre(cmdobj, "--help")
      rescue NoMethodError
	puts "Usage of command #{arg} failed"
      end
    when "!toc"
      puts table_of_contents()
    when "!toc-link"
      puts "''[http://rubygems.rubyforge.org/wiki/wiki.pl?GemReference#toc ^ Table of Contents]''"
    when "!version"
      puts Gem::RubyGemsPackageVersion
    end
  else
    puts line
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubygems-update-0.8.8 scripts/gemdoc.rb
rubygems-update-0.8.10 scripts/gemdoc.rb
rubygems-update-0.8.5 scripts/gemdoc.rb
rubygems-update-0.8.3 scripts/gemdoc.rb
rubygems-update-0.8.4 scripts/gemdoc.rb
rubygems-update-0.8.6 scripts/gemdoc.rb