mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Add --system, --site, --home and --gems to limit ri search path.
Allow --doc-dir to be specified mulitple times. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b73e6801e3
commit
90952d32f8
4 changed files with 126 additions and 38 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Mon Jun 26 11:03:00 2006 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
|
* lib/rdoc/ri: Add options to limit the ri search path.
|
||||||
|
|
||||||
Tue Jun 27 01:31:59 2006 Tanaka Akira <akr@m17n.org>
|
Tue Jun 27 01:31:59 2006 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
* ext/socket/socket.c (bsock_recv_nonblock): new method
|
* ext/socket/socket.c (bsock_recv_nonblock): new method
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
require 'rdoc/usage'
|
|
||||||
require 'rdoc/ri/ri_paths'
|
require 'rdoc/ri/ri_paths'
|
||||||
|
require 'rdoc/usage'
|
||||||
require 'rdoc/ri/ri_cache'
|
require 'rdoc/ri/ri_cache'
|
||||||
require 'rdoc/ri/ri_util'
|
require 'rdoc/ri/ri_util'
|
||||||
require 'rdoc/ri/ri_reader'
|
require 'rdoc/ri/ri_reader'
|
||||||
|
@ -21,20 +21,18 @@ class RiDriver
|
||||||
|
|
||||||
@options.parse(args)
|
@options.parse(args)
|
||||||
|
|
||||||
paths = @options.paths || RI::Paths::PATH
|
path = @options.path
|
||||||
if paths.empty?
|
report_missing_documentation @options.raw_path if path.empty?
|
||||||
report_missing_documentation(paths)
|
|
||||||
end
|
@ri_reader = RI::RiReader.new(RI::RiCache.new(path))
|
||||||
@ri_reader = RI::RiReader.new(RI::RiCache.new(paths))
|
|
||||||
@display = @options.displayer
|
@display = @options.displayer
|
||||||
end
|
end
|
||||||
|
|
||||||
# Couldn't find documentation in paths, so tell the user
|
# Couldn't find documentation in +path+, so tell the user what to do
|
||||||
# what to do
|
|
||||||
|
|
||||||
def report_missing_documentation(paths)
|
def report_missing_documentation(path)
|
||||||
STDERR.puts "No ri documentation found in:"
|
STDERR.puts "No ri documentation found in:"
|
||||||
paths.each do |d|
|
path.each do |d|
|
||||||
STDERR.puts " #{d}"
|
STDERR.puts " #{d}"
|
||||||
end
|
end
|
||||||
STDERR.puts "\nWas rdoc run to create documentation?\n\n"
|
STDERR.puts "\nWas rdoc run to create documentation?\n\n"
|
||||||
|
|
|
@ -45,7 +45,25 @@ module RI
|
||||||
|
|
||||||
[ "--doc-dir", "-d", "<dirname>",
|
[ "--doc-dir", "-d", "<dirname>",
|
||||||
"A directory to search for documentation. If not\n" +
|
"A directory to search for documentation. If not\n" +
|
||||||
"specified, we search the standard rdoc/ri directories."],
|
"specified, we search the standard rdoc/ri directories.\n" +
|
||||||
|
"May be repeated."],
|
||||||
|
|
||||||
|
[ "--system", nil, nil,
|
||||||
|
"Include documentation from Ruby's standard library:\n " +
|
||||||
|
RI::Paths::SYSDIR ],
|
||||||
|
|
||||||
|
[ "--site", nil, nil,
|
||||||
|
"Include documentation from libraries installed in site_lib:\n " +
|
||||||
|
RI::Paths::SITEDIR ],
|
||||||
|
|
||||||
|
[ "--home", nil, nil,
|
||||||
|
"Include documentation stored in ~/.rdoc:\n " +
|
||||||
|
(RI::Paths::HOMEDIR || "No ~/.rdoc found") ],
|
||||||
|
|
||||||
|
[ "--gems", nil, nil,
|
||||||
|
"Include documentation from Rubygems:\n " +
|
||||||
|
(RI::Paths::GEMDIRS ? "#{Gem.path}/doc/*/ri" :
|
||||||
|
"No Rubygems ri found.") ],
|
||||||
|
|
||||||
[ "--format", "-f", "<name>",
|
[ "--format", "-f", "<name>",
|
||||||
"Format to use when displaying output:\n" +
|
"Format to use when displaying output:\n" +
|
||||||
|
@ -74,10 +92,12 @@ module RI
|
||||||
|
|
||||||
def OptionList.options
|
def OptionList.options
|
||||||
OPTION_LIST.map do |long, short, arg,|
|
OPTION_LIST.map do |long, short, arg,|
|
||||||
[ long,
|
option = []
|
||||||
short,
|
option << long
|
||||||
arg ? GetoptLong::REQUIRED_ARGUMENT : GetoptLong::NO_ARGUMENT
|
option << short unless short.nil?
|
||||||
]
|
option << (arg ? GetoptLong::REQUIRED_ARGUMENT :
|
||||||
|
GetoptLong::NO_ARGUMENT)
|
||||||
|
option
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -108,6 +128,17 @@ module RI
|
||||||
puts
|
puts
|
||||||
|
|
||||||
name = File.basename($0)
|
name = File.basename($0)
|
||||||
|
|
||||||
|
directories = [
|
||||||
|
RI::Paths::SYSDIR,
|
||||||
|
RI::Paths::SITEDIR,
|
||||||
|
RI::Paths::HOMEDIR
|
||||||
|
]
|
||||||
|
|
||||||
|
directories << "#{Gem.path}/doc/*/ri" if RI::Paths::GEMDIRS
|
||||||
|
|
||||||
|
directories = directories.join("\n ")
|
||||||
|
|
||||||
OptionList.strip_output(<<-EOT)
|
OptionList.strip_output(<<-EOT)
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
|
@ -136,6 +167,15 @@ module RI
|
||||||
ri 'Array.[]'
|
ri 'Array.[]'
|
||||||
ri compact\\!
|
ri compact\\!
|
||||||
|
|
||||||
|
By default ri searches for documentation in the following
|
||||||
|
directories:
|
||||||
|
|
||||||
|
#{directories}
|
||||||
|
|
||||||
|
Specifying the --system, --site, --home, --gems or --doc-dir
|
||||||
|
options will limit ri to searching only the specified
|
||||||
|
directories.
|
||||||
|
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
if short_form
|
if short_form
|
||||||
|
@ -144,7 +184,9 @@ module RI
|
||||||
else
|
else
|
||||||
puts "Options:\n\n"
|
puts "Options:\n\n"
|
||||||
OPTION_LIST.each do|long, short, arg, desc|
|
OPTION_LIST.each do|long, short, arg, desc|
|
||||||
opt = sprintf("%15s", "#{long}, #{short}")
|
opt = ''
|
||||||
|
opt << (short ? sprintf("%15s", "#{long}, #{short}") :
|
||||||
|
sprintf("%15s", long))
|
||||||
if arg
|
if arg
|
||||||
opt << " " << arg
|
opt << " " << arg
|
||||||
end
|
end
|
||||||
|
@ -173,24 +215,27 @@ module RI
|
||||||
exit(0)
|
exit(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@use_stdout = !STDOUT.tty?
|
@use_stdout = !STDOUT.tty?
|
||||||
@width = 72
|
@width = 72
|
||||||
@formatter = RI::TextFormatter.for("plain")
|
@formatter = RI::TextFormatter.for("plain")
|
||||||
@list_classes = false
|
@list_classes = false
|
||||||
@list_names = false
|
@list_names = false
|
||||||
end
|
|
||||||
|
|
||||||
|
# By default all paths are used. If any of these are true, only those
|
||||||
|
# directories are used.
|
||||||
|
@use_system = false
|
||||||
|
@use_site = false
|
||||||
|
@use_home = false
|
||||||
|
@use_gems = false
|
||||||
|
@doc_dirs = []
|
||||||
|
end
|
||||||
|
|
||||||
# Parse command line options.
|
# Parse command line options.
|
||||||
|
|
||||||
def parse(args)
|
def parse(args)
|
||||||
|
|
||||||
old_argv = ARGV.dup
|
old_argv = ARGV.dup
|
||||||
# if ENV["RI"]
|
|
||||||
# ARGV.replace(ENV["RI"].split.concat(ARGV))
|
|
||||||
# end
|
|
||||||
|
|
||||||
ARGV.replace(args)
|
ARGV.replace(args)
|
||||||
|
|
||||||
|
@ -206,9 +251,15 @@ module RI
|
||||||
when "--list-names" then @list_names = true
|
when "--list-names" then @list_names = true
|
||||||
when "--no-pager" then @use_stdout = true
|
when "--no-pager" then @use_stdout = true
|
||||||
when "--classes" then @list_classes = true
|
when "--classes" then @list_classes = true
|
||||||
|
|
||||||
|
when "--system" then @use_system = true
|
||||||
|
when "--site" then @use_site = true
|
||||||
|
when "--home" then @use_home = true
|
||||||
|
when "--gems" then @use_gems = true
|
||||||
|
|
||||||
when "--doc-dir"
|
when "--doc-dir"
|
||||||
if File.directory?(arg)
|
if File.directory?(arg)
|
||||||
@doc_dir = arg
|
@doc_dirs << arg
|
||||||
else
|
else
|
||||||
$stderr.puts "Invalid directory: #{arg}"
|
$stderr.puts "Invalid directory: #{arg}"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -237,9 +288,15 @@ module RI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the doc_dir as an array, or nil if no overriding doc dir was given
|
# Return the selected documentation directories.
|
||||||
def paths
|
|
||||||
defined?(@doc_dir) ? [ @doc_dir ] : nil
|
def path
|
||||||
|
RI::Paths.path(@use_system, @use_site, @use_home, @use_gems, *@doc_dirs)
|
||||||
|
end
|
||||||
|
|
||||||
|
def raw_path
|
||||||
|
RI::Paths.raw_path(@use_system, @use_site, @use_home, @use_gems,
|
||||||
|
*@doc_dirs)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return an instance of the displayer (the thing that actually writes
|
# Return an instance of the displayer (the thing that actually writes
|
||||||
|
|
|
@ -44,8 +44,37 @@ module RI
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
Dir["#{Gem.path}/doc/*/ri"].each { |path| RI::Paths::PATH << path }
|
GEMDIRS = Dir["#{Gem.path}/doc/*/ri"]
|
||||||
|
GEMDIRS.each { |path| RI::Paths::PATH << path }
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
end
|
GEMDIRS = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the selected documentation directories as an Array, or PATH if no
|
||||||
|
# overriding directories were given.
|
||||||
|
|
||||||
|
def self.path(use_system, use_site, use_home, use_gems, *extra_dirs)
|
||||||
|
path = raw_path(use_system, use_site, use_home, use_gems, *extra_dirs)
|
||||||
|
return path.select { |path| File.directory? path }
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the selected documentation directories including nonexistent
|
||||||
|
# directories. Used to print out what paths were searched if no ri was
|
||||||
|
# found.
|
||||||
|
|
||||||
|
def self.raw_path(use_system, use_site, use_home, use_gems, *extra_dirs)
|
||||||
|
return PATH unless use_system or use_site or use_home or use_gems or
|
||||||
|
not extra_dirs.empty?
|
||||||
|
|
||||||
|
path = []
|
||||||
|
path << extra_dirs unless extra_dirs.empty?
|
||||||
|
path << RI::Paths::SYSDIR if use_system
|
||||||
|
path << RI::Paths::SITEDIR if use_site
|
||||||
|
path << RI::Paths::HOMEDIR if use_home
|
||||||
|
path << RI::Paths::GEMDIRS if use_gems
|
||||||
|
|
||||||
|
return path.flatten.compact
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue