summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-26 18:10:30 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-26 18:10:30 +0000
commit90952d32f80e3733e9895f296aea067a828d0143 (patch)
tree5a9f6a60c7ea00f3fb92924d41f4119e6e00834a
parentb73e6801e30e4bd8f57d2f54cb479deaf95b74fb (diff)
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
-rw-r--r--ChangeLog4
-rw-r--r--lib/rdoc/ri/ri_driver.rb20
-rw-r--r--lib/rdoc/ri/ri_options.rb105
-rw-r--r--lib/rdoc/ri/ri_paths.rb31
4 files changed, 124 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index b6b98dc325..5ebf0b308a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* ext/socket/socket.c (bsock_recv_nonblock): new method
diff --git a/lib/rdoc/ri/ri_driver.rb b/lib/rdoc/ri/ri_driver.rb
index d2545bb1da..a00f20ee3b 100644
--- a/lib/rdoc/ri/ri_driver.rb
+++ b/lib/rdoc/ri/ri_driver.rb
@@ -1,5 +1,5 @@
-require 'rdoc/usage'
require 'rdoc/ri/ri_paths'
+require 'rdoc/usage'
require 'rdoc/ri/ri_cache'
require 'rdoc/ri/ri_util'
require 'rdoc/ri/ri_reader'
@@ -21,20 +21,18 @@ class RiDriver
@options.parse(args)
- paths = @options.paths || RI::Paths::PATH
- if paths.empty?
- report_missing_documentation(paths)
- end
- @ri_reader = RI::RiReader.new(RI::RiCache.new(paths))
+ path = @options.path
+ report_missing_documentation @options.raw_path if path.empty?
+
+ @ri_reader = RI::RiReader.new(RI::RiCache.new(path))
@display = @options.displayer
- end
+ end
- # Couldn't find documentation in paths, so tell the user
- # what to do
+ # Couldn't find documentation in +path+, so tell the user what to do
- def report_missing_documentation(paths)
+ def report_missing_documentation(path)
STDERR.puts "No ri documentation found in:"
- paths.each do |d|
+ path.each do |d|
STDERR.puts " #{d}"
end
STDERR.puts "\nWas rdoc run to create documentation?\n\n"
diff --git a/lib/rdoc/ri/ri_options.rb b/lib/rdoc/ri/ri_options.rb
index 5ee9a45588..91a28e1ab4 100644
--- a/lib/rdoc/ri/ri_options.rb
+++ b/lib/rdoc/ri/ri_options.rb
@@ -37,23 +37,41 @@ module RI
OPTION_LIST = [
[ "--help", "-h", nil,
- "you're looking at it" ],
+ "you're looking at it" ],
[ "--classes", "-c", nil,
"Display the names of classes and modules we\n" +
"know about"],
[ "--doc-dir", "-d", "<dirname>",
- "A directory to search for documentation. If not\n"+
- "specified, we search the standard rdoc/ri directories."],
+ "A directory to search for documentation. If not\n" +
+ "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 to use when displaying output:\n" +
- " " + RI::TextFormatter.list + "\n" +
- "Use 'bs' (backspace) with most pager programs.\n" +
- "To use ANSI, either also use the -T option, or\n" +
- "tell your pager to allow control characters\n" +
- "(for example using the -R option to less)"],
+ "Format to use when displaying output:\n" +
+ " " + RI::TextFormatter.list + "\n" +
+ "Use 'bs' (backspace) with most pager programs.\n" +
+ "To use ANSI, either also use the -T option, or\n" +
+ "tell your pager to allow control characters\n" +
+ "(for example using the -R option to less)"],
[ "--list-names", "-l", nil,
"List all the names known to RDoc, one per line"
@@ -74,10 +92,12 @@ module RI
def OptionList.options
OPTION_LIST.map do |long, short, arg,|
- [ long,
- short,
- arg ? GetoptLong::REQUIRED_ARGUMENT : GetoptLong::NO_ARGUMENT
- ]
+ option = []
+ option << long
+ option << short unless short.nil?
+ option << (arg ? GetoptLong::REQUIRED_ARGUMENT :
+ GetoptLong::NO_ARGUMENT)
+ option
end
end
@@ -108,6 +128,17 @@ module RI
puts
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)
Usage:
@@ -136,6 +167,15 @@ module RI
ri 'Array.[]'
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
if short_form
@@ -144,7 +184,9 @@ module RI
else
puts "Options:\n\n"
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
opt << " " << arg
end
@@ -173,26 +215,29 @@ module RI
exit(0)
end
-
def initialize
@use_stdout = !STDOUT.tty?
@width = 72
@formatter = RI::TextFormatter.for("plain")
@list_classes = 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.
def parse(args)
old_argv = ARGV.dup
-# if ENV["RI"]
-# ARGV.replace(ENV["RI"].split.concat(ARGV))
-# end
- ARGV.replace(args)
+ ARGV.replace(args)
begin
@@ -206,9 +251,15 @@ module RI
when "--list-names" then @list_names = true
when "--no-pager" then @use_stdout = 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"
if File.directory?(arg)
- @doc_dir = arg
+ @doc_dirs << arg
else
$stderr.puts "Invalid directory: #{arg}"
exit 1
@@ -237,9 +288,15 @@ module RI
end
end
- # Return the doc_dir as an array, or nil if no overriding doc dir was given
- def paths
- defined?(@doc_dir) ? [ @doc_dir ] : nil
+ # Return the selected documentation directories.
+
+ 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
# Return an instance of the displayer (the thing that actually writes
diff --git a/lib/rdoc/ri/ri_paths.rb b/lib/rdoc/ri/ri_paths.rb
index c5526201ea..4a67e44ba5 100644
--- a/lib/rdoc/ri/ri_paths.rb
+++ b/lib/rdoc/ri/ri_paths.rb
@@ -44,8 +44,37 @@ module RI
begin
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
+ 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