Skip to content

Commit 210ab2c

Browse files
authored
Merge pull request #448 from stomar/ri-help
Improve ri --help and --version options handling
2 parents 5f11ddf + 853d56f commit 210ab2c

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

lib/rdoc/ri/driver.rb

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def self.process_args argv
122122
opt.summary_indent = ' ' * 4
123123

124124
opt.banner = <<-EOT
125-
Usage: #{opt.program_name} [options] [names...]
125+
Usage: #{opt.program_name} [options] [name ...]
126126
127127
Where name can be:
128128
@@ -132,8 +132,8 @@ def self.process_args argv
132132
133133
gem_name: | gem_name:README | gem_name:History
134134
135-
All class names may be abbreviated to their minimum unambiguous form. If a name
136-
is ambiguous, all valid options will be listed.
135+
All class names may be abbreviated to their minimum unambiguous form.
136+
If a name is ambiguous, all valid options will be listed.
137137
138138
A '.' matches either class or instance methods, while #method
139139
matches only instance and ::method matches only class methods.
@@ -151,23 +151,23 @@ def self.process_args argv
151151
#{opt.program_name} zip
152152
#{opt.program_name} rdoc:README
153153
154-
Note that shell quoting or escaping may be required for method names containing
155-
punctuation:
154+
Note that shell quoting or escaping may be required for method names
155+
containing punctuation:
156156
157157
#{opt.program_name} 'Array.[]'
158158
#{opt.program_name} compact\\!
159159
160-
To see the default directories ri will search, run:
160+
To see the default directories #{opt.program_name} will search, run:
161161
162162
#{opt.program_name} --list-doc-dirs
163163
164-
Specifying the --system, --site, --home, --gems or --doc-dir options will
165-
limit ri to searching only the specified directories.
164+
Specifying the --system, --site, --home, --gems, or --doc-dir options
165+
will limit ri to searching only the specified directories.
166166
167-
ri options may be set in the 'RI' environment variable.
167+
ri options may be set in the RI environment variable.
168168
169-
The ri pager can be set with the 'RI_PAGER' environment variable or the
170-
'PAGER' environment variable.
169+
The ri pager can be set with the RI_PAGER environment variable
170+
or the PAGER environment variable.
171171
EOT
172172

173173
opt.separator nil
@@ -199,15 +199,15 @@ def self.process_args argv
199199
opt.separator nil
200200

201201
opt.on("--[no-]pager",
202-
"Send output directly to stdout,",
203-
"rather than to a pager.") do |use_pager|
202+
"Send output to a pager,",
203+
"rather than directly to stdout.") do |use_pager|
204204
options[:use_stdout] = !use_pager
205205
end
206206

207207
opt.separator nil
208208

209209
opt.on("-T",
210-
"Synonym for --no-pager") do
210+
"Synonym for --no-pager.") do
211211
options[:use_stdout] = true
212212
end
213213

@@ -220,7 +220,7 @@ def self.process_args argv
220220

221221
opt.separator nil
222222

223-
opt.on("--server [PORT]", Integer,
223+
opt.on("--server[=PORT]", Integer,
224224
"Run RDoc server on the given port.",
225225
"The default port is 8214.") do |port|
226226
options[:server] = port || 8214
@@ -235,13 +235,29 @@ def self.process_args argv
235235
formatters -= %w[html label test] # remove useless output formats
236236

237237
opt.on("--format=NAME", "-f",
238-
"Uses the selected formatter. The default",
238+
"Use the selected formatter. The default",
239239
"formatter is bs for paged output and ansi",
240-
"otherwise. Valid formatters are:",
241-
formatters.join(' '), formatters) do |value|
240+
"otherwise. Valid formatters are:",
241+
"#{formatters.join(', ')}.", formatters) do |value|
242242
options[:formatter] = RDoc::Markup.const_get "To#{value.capitalize}"
243243
end
244244

245+
opt.separator nil
246+
247+
opt.on("--help", "-h",
248+
"Show help and exit.") do
249+
puts opts
250+
exit
251+
end
252+
253+
opt.separator nil
254+
255+
opt.on("--version", "-v",
256+
"Output version information and exit.") do
257+
puts "#{opts.program_name} #{opts.version}"
258+
exit
259+
end
260+
245261
opt.separator nil
246262
opt.separator "Data source options:"
247263
opt.separator nil
@@ -273,7 +289,7 @@ def self.process_args argv
273289
"Do not include documentation from",
274290
"the Ruby standard library, site_lib,",
275291
"installed gems, or ~/.rdoc.",
276-
"Use with --doc-dir") do
292+
"Use with --doc-dir.") do
277293
options[:use_system] = false
278294
options[:use_site] = false
279295
options[:use_gems] = false
@@ -283,8 +299,8 @@ def self.process_args argv
283299
opt.separator nil
284300

285301
opt.on("--[no-]system",
286-
"Include documentation from Ruby's standard",
287-
"library. Defaults to true.") do |value|
302+
"Include documentation from Ruby's",
303+
"standard library. Defaults to true.") do |value|
288304
options[:use_system] = value
289305
end
290306

@@ -318,14 +334,14 @@ def self.process_args argv
318334
opt.separator nil
319335

320336
opt.on("--[no-]profile",
321-
"Run with the ruby profiler") do |value|
337+
"Run with the ruby profiler.") do |value|
322338
options[:profile] = value
323339
end
324340

325341
opt.separator nil
326342

327343
opt.on("--dump=CACHE", File,
328-
"Dumps data from an ri cache or data file") do |value|
344+
"Dump data from an ri cache or data file.") do |value|
329345
options[:dump_path] = value
330346
end
331347
end

0 commit comments

Comments
 (0)