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/branches/ruby_1_8@6020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
aa8658f7b1
commit
3ae6e3ccbf
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>
|
Thu Mar 25 03:57:47 2004 Dave Thomas <dave@pragprog.com>
|
||||||
|
|
||||||
* lib/rdoc/ri/ri_util.rb (NameDescriptor::initialize): No longer
|
* lib/rdoc/ri/ri_util.rb (NameDescriptor::initialize): No longer
|
||||||
|
|
|
@ -87,6 +87,13 @@ module RI
|
||||||
res << @name
|
res << @name
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
# Return a list of all our methods matching a given string.
|
# Return a list of all our methods matching a given string.
|
||||||
|
|
|
@ -165,8 +165,7 @@ class DefaultDisplay
|
||||||
|
|
||||||
def list_known_classes(classes)
|
def list_known_classes(classes)
|
||||||
if classes.empty?
|
if classes.empty?
|
||||||
puts "Before using ri, you need to generate documentation"
|
warn_no_database
|
||||||
puts "using 'rdoc' with the --ri option"
|
|
||||||
else
|
else
|
||||||
page do
|
page do
|
||||||
@formatter.draw_line("Known classes and modules")
|
@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
|
private
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
@ -242,7 +253,12 @@ class DefaultDisplay
|
||||||
@formatter.break_to_newline
|
@formatter.break_to_newline
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
def warn_no_database
|
||||||
|
puts "Before using ri, you need to generate documentation"
|
||||||
|
puts "using 'rdoc' with the --ri option"
|
||||||
|
end
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def display_flow(flow)
|
def display_flow(flow)
|
||||||
|
|
|
@ -110,6 +110,9 @@ class RiDriver
|
||||||
if @options.list_classes
|
if @options.list_classes
|
||||||
classes = @ri_reader.full_class_names
|
classes = @ri_reader.full_class_names
|
||||||
@display.list_known_classes(classes)
|
@display.list_known_classes(classes)
|
||||||
|
elsif @options.list_names
|
||||||
|
names = @ri_reader.all_names
|
||||||
|
@display.list_known_names(names)
|
||||||
else
|
else
|
||||||
if ARGV.size.zero?
|
if ARGV.size.zero?
|
||||||
@display.display_usage
|
@display.display_usage
|
||||||
|
|
|
@ -83,6 +83,12 @@ module RI
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
def raw_print_line(txt)
|
||||||
|
puts txt
|
||||||
|
end
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
|
||||||
# convert HTML entities back to ASCII
|
# convert HTML entities back to ASCII
|
||||||
def conv_html(txt)
|
def conv_html(txt)
|
||||||
txt.
|
txt.
|
||||||
|
|
|
@ -21,6 +21,9 @@ module RI
|
||||||
# should we just display a class list and exit
|
# should we just display a class list and exit
|
||||||
attr_reader :list_classes
|
attr_reader :list_classes
|
||||||
|
|
||||||
|
# should we display a list of all names
|
||||||
|
attr_reader :list_names
|
||||||
|
|
||||||
# The width of the output line
|
# The width of the output line
|
||||||
attr_reader :width
|
attr_reader :width
|
||||||
|
|
||||||
|
@ -52,6 +55,10 @@ module RI
|
||||||
"tell your pager to allow control characters\n" +
|
"tell your pager to allow control characters\n" +
|
||||||
"(for example using the -R option to less)"],
|
"(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,
|
[ "--no-pager", "-T", nil,
|
||||||
"Send output directly to stdout."
|
"Send output directly to stdout."
|
||||||
],
|
],
|
||||||
|
@ -163,7 +170,8 @@ module RI
|
||||||
@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
|
||||||
|
|
||||||
old_argv = ARGV.dup
|
old_argv = ARGV.dup
|
||||||
if ENV["RI"]
|
if ENV["RI"]
|
||||||
|
@ -177,10 +185,11 @@ module RI
|
||||||
|
|
||||||
go.each do |opt, arg|
|
go.each do |opt, arg|
|
||||||
case opt
|
case opt
|
||||||
when "--help" then OptionList.usage
|
when "--help" then OptionList.usage
|
||||||
when "--no-pager" then @use_stdout = true
|
when "--list-names" then @list_names = true
|
||||||
when "--classes" then @list_classes = true
|
when "--no-pager" then @use_stdout = true
|
||||||
when "--doc-dir" then @doc_dir = arg
|
when "--classes" then @list_classes = true
|
||||||
|
when "--doc-dir" then @doc_dir = arg
|
||||||
|
|
||||||
when "--format"
|
when "--format"
|
||||||
@formatter = RI::TextFormatter.for(arg)
|
@formatter = RI::TextFormatter.for(arg)
|
||||||
|
|
|
@ -58,6 +58,16 @@ module RI
|
||||||
find_classes_in(res, @cache.toplevel)
|
find_classes_in(res, @cache.toplevel)
|
||||||
end
|
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)
|
def find_classes_in(res, klass)
|
||||||
classes = klass.classes_and_modules
|
classes = klass.classes_and_modules
|
||||||
for c in classes
|
for c in classes
|
||||||
|
@ -66,5 +76,16 @@ module RI
|
||||||
end
|
end
|
||||||
res
|
res
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue