Skip to content

Commit e815c30

Browse files
committed
Add ri --list and make interactive ri the default if no names are given
1 parent 38354a7 commit e815c30

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

History.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
=== 3.6
22

3+
* Major Enhancements
4+
* Interactive ri is now the default when no names are given.
35
* Minor Enhancements
46
* RDoc::RDoc#generate was added to allow multiple generators to be used with
57
a set of parsed file info.
68
* RDoc::Options#finish can be called multiple times now.
79
* `ri -i` only shows one level of namespace when completing class names.
10+
* Added `ri --list` for explicit listing. `ri -l F G` will list all classes
11+
or modules starting with F or G
812
* Bug fixes
913
* Remove windows-specific test for test_check_files, it is too hard to do.
1014
Ruby commit r30811 by Usaku Nakamura.

lib/rdoc/ri/driver.rb

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ def self.process_args argv
197197

198198
opt.separator nil
199199

200+
opt.on("--list", "-l",
201+
"List classes ri knows about.") do
202+
options[:list] = true
203+
end
204+
205+
opt.separator nil
206+
200207
opt.on("--[no-]profile",
201208
"Run with the ruby profiler") do |value|
202209
options[:profile] = value
@@ -331,6 +338,7 @@ def initialize initial_options = {}
331338
require 'profile' if options[:profile]
332339

333340
@names = options[:names]
341+
@list = options[:list]
334342

335343
@doc_dirs = []
336344
@stores = []
@@ -881,9 +889,10 @@ def in_path? file
881889
end
882890

883891
##
884-
# Lists classes known to ri
892+
# Lists classes known to ri starting with +names+. If +names+ is empty all
893+
# known classes are shown.
885894

886-
def list_known_classes
895+
def list_known_classes names = []
887896
classes = []
888897

889898
stores.each do |store|
@@ -892,9 +901,19 @@ def list_known_classes
892901

893902
classes = classes.flatten.uniq.sort
894903

904+
unless names.empty? then
905+
filter = Regexp.union names.map { |name| /^#{name}/ }
906+
907+
classes = classes.grep filter
908+
end
909+
895910
page do |io|
896911
if paging? or io.tty? then
897-
io.puts "Classes and Modules known to ri:"
912+
if names.empty? then
913+
io.puts "Classes and Modules known to ri:"
914+
else
915+
io.puts "Classes and Modules starting with #{names.join ', '}:"
916+
end
898917
io.puts
899918
end
900919

@@ -1067,10 +1086,10 @@ def parse_name(name)
10671086
def run
10681087
if @list_doc_dirs then
10691088
puts @doc_dirs
1070-
elsif @interactive then
1089+
elsif @list then
1090+
list_known_classes @names
1091+
elsif @interactive or @names.empty? then
10711092
interactive
1072-
elsif @names.empty? then
1073-
list_known_classes
10741093
else
10751094
display_names @names
10761095
end

test/test_rdoc_ri_driver.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,16 @@ def test_list_known_classes
600600
assert_equal "Ambiguous\nFoo\nFoo::Bar\nFoo::Baz\nInc\n", out
601601
end
602602

603+
def test_list_known_classes_name
604+
util_store
605+
606+
out, = capture_io do
607+
@driver.list_known_classes %w[F I]
608+
end
609+
610+
assert_equal "Foo\nFoo::Bar\nFoo::Baz\nInc\n", out
611+
end
612+
603613
def test_list_methods_matching
604614
util_store
605615

0 commit comments

Comments
 (0)