summaryrefslogtreecommitdiff
path: root/lib/rdoc/ri/ri_options.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rdoc/ri/ri_options.rb')
-rw-r--r--lib/rdoc/ri/ri_options.rb105
1 files changed, 81 insertions, 24 deletions
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