From e147632bffc50fd33f5b5d6f5716e3627985c0d1 Mon Sep 17 00:00:00 2001 From: dave Date: Wed, 24 Mar 2004 19:17:42 +0000 Subject: Add the --list-names option git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ lib/rdoc/ri/ri_cache.rb | 7 +++++++ lib/rdoc/ri/ri_display.rb | 22 +++++++++++++++++++--- lib/rdoc/ri/ri_driver.rb | 3 +++ lib/rdoc/ri/ri_formatter.rb | 6 ++++++ lib/rdoc/ri/ri_options.rb | 19 ++++++++++++++----- lib/rdoc/ri/ri_reader.rb | 21 +++++++++++++++++++++ 7 files changed, 75 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index b25006d2c1..8e3b859370 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Mar 25 04:16:18 2004 Dave Thomas + + * lib/rdoc/ri/ri_options.rb (RI::Options): Add the --list-names option, + which dumps our all known names + Thu Mar 25 03:57:47 2004 Dave Thomas * lib/rdoc/ri/ri_util.rb (NameDescriptor::initialize): No longer diff --git a/lib/rdoc/ri/ri_cache.rb b/lib/rdoc/ri/ri_cache.rb index 8d7c982409..189817485b 100644 --- a/lib/rdoc/ri/ri_cache.rb +++ b/lib/rdoc/ri/ri_cache.rb @@ -87,6 +87,13 @@ module RI res << @name end + # Return a list of all out method names + def all_method_names + res = @class_methods.map {|m| m.full_name } + @instance_methods.each {|m| res << m.full_name} + res + end + private # Return a list of all our methods matching a given string. diff --git a/lib/rdoc/ri/ri_display.rb b/lib/rdoc/ri/ri_display.rb index 1e371350dc..8e5d07ee6c 100644 --- a/lib/rdoc/ri/ri_display.rb +++ b/lib/rdoc/ri/ri_display.rb @@ -165,8 +165,7 @@ class DefaultDisplay def list_known_classes(classes) if classes.empty? - puts "Before using ri, you need to generate documentation" - puts "using 'rdoc' with the --ri option" + warn_no_database else page do @formatter.draw_line("Known classes and modules") @@ -178,6 +177,18 @@ class DefaultDisplay ###################################################################### + def list_known_names(names) + if names.empty? + warn_no_database + else + page do + names.each {|n| @formatter.raw_print_line(n)} + end + end + end + + ###################################################################### + private ###################################################################### @@ -236,5 +247,10 @@ class DefaultDisplay end end - + ###################################################################### + + def warn_no_database + puts "Before using ri, you need to generate documentation" + puts "using 'rdoc' with the --ri option" + end end # class RiDisplay diff --git a/lib/rdoc/ri/ri_driver.rb b/lib/rdoc/ri/ri_driver.rb index f6058cd51c..afefa67dc2 100644 --- a/lib/rdoc/ri/ri_driver.rb +++ b/lib/rdoc/ri/ri_driver.rb @@ -110,6 +110,9 @@ class RiDriver if @options.list_classes classes = @ri_reader.full_class_names @display.list_known_classes(classes) + elsif @options.list_names + names = @ri_reader.all_names + @display.list_known_names(names) else if ARGV.size.zero? @display.display_usage diff --git a/lib/rdoc/ri/ri_formatter.rb b/lib/rdoc/ri/ri_formatter.rb index dfc5d031d5..63c12aaced 100644 --- a/lib/rdoc/ri/ri_formatter.rb +++ b/lib/rdoc/ri/ri_formatter.rb @@ -83,6 +83,12 @@ module RI ###################################################################### + def raw_print_line(txt) + puts txt + end + + ###################################################################### + # convert HTML entities back to ASCII def conv_html(txt) txt. diff --git a/lib/rdoc/ri/ri_options.rb b/lib/rdoc/ri/ri_options.rb index 8aec57e9a1..d9ece2067c 100644 --- a/lib/rdoc/ri/ri_options.rb +++ b/lib/rdoc/ri/ri_options.rb @@ -21,6 +21,9 @@ module RI # should we just display a class list and exit attr_reader :list_classes + # should we display a list of all names + attr_reader :list_names + # The width of the output line attr_reader :width @@ -52,6 +55,10 @@ module RI "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" + ], + [ "--no-pager", "-T", nil, "Send output directly to stdout." ], @@ -163,7 +170,8 @@ module RI @use_stdout = !STDOUT.tty? @width = 72 @formatter = RI::TextFormatter.for("plain") - @list_classes = false + @list_classes = false + @list_names = false old_argv = ARGV.dup if ENV["RI"] @@ -177,10 +185,11 @@ module RI go.each do |opt, arg| case opt - when "--help" then OptionList.usage - when "--no-pager" then @use_stdout = true - when "--classes" then @list_classes = true - when "--doc-dir" then @doc_dir = arg + when "--help" then OptionList.usage + when "--list-names" then @list_names = true + when "--no-pager" then @use_stdout = true + when "--classes" then @list_classes = true + when "--doc-dir" then @doc_dir = arg when "--format" @formatter = RI::TextFormatter.for(arg) diff --git a/lib/rdoc/ri/ri_reader.rb b/lib/rdoc/ri/ri_reader.rb index 02e6d49b79..6e53bd2609 100644 --- a/lib/rdoc/ri/ri_reader.rb +++ b/lib/rdoc/ri/ri_reader.rb @@ -58,6 +58,16 @@ module RI find_classes_in(res, @cache.toplevel) end + # return a list of all classes, modules, and methods + def all_names + res = [] + find_names_in(res, @cache.toplevel) + end + + # ---- + private + # ---- + def find_classes_in(res, klass) classes = klass.classes_and_modules for c in classes @@ -66,5 +76,16 @@ module RI end res end + + def find_names_in(res, klass) + classes = klass.classes_and_modules + for c in classes + res << c.full_name + res.concat c.all_method_names + find_names_in(res, c) + end + res + end + end end -- cgit v1.2.3