mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Add the --list-names option
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
16040850af
commit
e147632bff
7 changed files with 75 additions and 8 deletions
|
@ -1,3 +1,8 @@
|
|||
Thu Mar 25 04:16:18 2004 Dave Thomas <dave@pragprog.com>
|
||||
|
||||
* 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 <dave@pragprog.com>
|
||||
|
||||
* lib/rdoc/ri/ri_util.rb (NameDescriptor::initialize): No longer
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue