2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/command'
|
|
|
|
require 'rubygems/version_option'
|
2012-11-29 01:52:18 -05:00
|
|
|
require 'rubygems/rdoc'
|
2012-12-14 00:09:37 -05:00
|
|
|
require 'fileutils'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
class Gem::Commands::RdocCommand < Gem::Command
|
|
|
|
include Gem::VersionOption
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def initialize
|
|
|
|
super 'rdoc', 'Generates RDoc for pre-installed gems',
|
|
|
|
:version => Gem::Requirement.default,
|
2012-11-29 01:52:18 -05:00
|
|
|
:include_rdoc => false, :include_ri => true, :overwrite => false
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
add_option('--all',
|
|
|
|
'Generate RDoc/RI documentation for all',
|
|
|
|
'installed gems') do |value, options|
|
|
|
|
options[:all] = value
|
|
|
|
end
|
|
|
|
|
|
|
|
add_option('--[no-]rdoc',
|
2010-02-21 21:52:35 -05:00
|
|
|
'Generate RDoc HTML') do |value, options|
|
2009-06-09 17:38:59 -04:00
|
|
|
options[:include_rdoc] = value
|
|
|
|
end
|
|
|
|
|
|
|
|
add_option('--[no-]ri',
|
2010-02-21 21:52:35 -05:00
|
|
|
'Generate RI data') do |value, options|
|
2009-06-09 17:38:59 -04:00
|
|
|
options[:include_ri] = value
|
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
add_option('--[no-]overwrite',
|
|
|
|
'Overwrite installed documents') do |value, options|
|
|
|
|
options[:overwrite] = value
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
add_version_option
|
|
|
|
end
|
|
|
|
|
|
|
|
def arguments # :nodoc:
|
|
|
|
"GEMNAME gem to generate documentation for (unless --all)"
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def defaults_str # :nodoc:
|
2012-11-29 01:52:18 -05:00
|
|
|
"--version '#{Gem::Requirement.default}' --ri --no-overwrite"
|
2010-02-21 21:52:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def description # :nodoc:
|
|
|
|
<<-DESC
|
2013-08-26 16:24:51 -04:00
|
|
|
The rdoc command builds documentation for installed gems. By default
|
|
|
|
only documentation is built using rdoc, but additional types of
|
|
|
|
documentation may be built through rubygems plugins and the
|
|
|
|
Gem.post_installs hook.
|
|
|
|
|
|
|
|
Use --overwrite to force rebuilding of documentation.
|
2010-02-21 21:52:35 -05:00
|
|
|
DESC
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def usage # :nodoc:
|
|
|
|
"#{program_name} [args]"
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2012-11-29 01:52:18 -05:00
|
|
|
specs = if options[:all] then
|
|
|
|
Gem::Specification.to_a
|
|
|
|
else
|
|
|
|
get_all_gem_names.map do |name|
|
|
|
|
Gem::Specification.find_by_name name, options[:version]
|
|
|
|
end.flatten.uniq
|
|
|
|
end
|
|
|
|
|
|
|
|
if specs.empty? then
|
|
|
|
alert_error 'No matching gems found'
|
|
|
|
terminate_interaction 1
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
specs.each do |spec|
|
|
|
|
doc = Gem::RDoc.new spec, options[:include_rdoc], options[:include_ri]
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
doc.force = options[:overwrite]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
if options[:overwrite] then
|
|
|
|
FileUtils.rm_rf File.join(spec.doc_dir, 'ri')
|
|
|
|
FileUtils.rm_rf File.join(spec.doc_dir, 'rdoc')
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
begin
|
|
|
|
doc.generate
|
|
|
|
rescue Errno::ENOENT => e
|
|
|
|
e.message =~ / - /
|
|
|
|
alert_error "Unable to document #{spec.full_name}, #{$'} is missing, skipping"
|
|
|
|
terminate_interaction 1 if specs.length == 1
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-02-21 21:52:35 -05:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
|