Parent

RDoc::Options

RDoc::Options handles the parsing and storage of options

Attributes

charset[R]

Character-set

exclude[RW]

Files matching this pattern will be excluded

files[RW]

The list of files to be processed

force_update[R]

Scan newer sources than the flag file if true.

generator[RW]

Description of the output generator (set with the -fmt option)

formatter[RW]

Formatter to mark up text with

main_page[RW]

Name of the file, class or module to display in the initial index page (if not specified the first file we encounter is used)

op_dir[RW]

The name of the output directory

pipe[RW]

Is RDoc in pipe mode?

rdoc_include[R]

Array of directories to search for files to satisfy an :include:

show_hash[R]

Include the ’#’ at the front of hyperlinked instance method names

tab_width[R]

The number of columns in a tab

template[R]

Template to be used when generating output

title[R]

Documentation title

verbosity[RW]

Verbosity, zero means quiet

webcvs[R]

URL of web cvs frontend

Public Instance Methods

parse(argv) click to toggle source

Parse command line options.

     # File lib/rdoc/options.rb, line 116
116:   def parse(argv)
117:     ignore_invalid = true
118: 
119:     opts = OptionParser.new do |opt|
120:       opt.program_name = File.basename $0
121:       opt.version = RDoc::VERSION
122:       opt.release = nil
123:       opt.summary_indent = ' ' * 4
124:       opt.banner = Usage: #{opt.program_name} [options] [names...]  Files are parsed, and the information they contain collected, before any  output is produced. This allows cross references between all files to be  resolved. If a name is a directory, it is traversed. If no names are  specified, all Ruby files in the current directory (and subdirectories) are  processed.  How RDoc generates output depends on the output formatter being used, and on  the options you give.  - Darkfish creates frameless HTML output by Michael Granger.  - ri creates ri data files  RDoc understands the following file formats:
125: 
126:       parsers = Hash.new { |h,parser| h[parser] = [] }
127: 
128:       RDoc::Parser.parsers.each do |regexp, parser|
129:         parsers[parser.name.sub('RDoc::Parser::', '')] << regexp.source
130:       end
131: 
132:       parsers.sort.each do |parser, regexp|
133:         opt.banner << "  - #{parser}: #{regexp.join ', '}\n"
134:       end
135: 
136:       opt.separator nil
137:       opt.separator "Parsing Options:"
138:       opt.separator nil
139: 
140:       opt.on("--exclude=PATTERN", "-x", Regexp,
141:              "Do not process files or directories",
142:              "matching PATTERN.") do |value|
143:         @exclude << value
144:       end
145: 
146:       opt.separator nil
147: 
148:       opt.on("--extension=NEW=OLD", "-E",
149:              "Treat files ending with .new as if they",
150:              "ended with .old. Using '-E cgi=rb' will",
151:              "cause xxx.cgi to be parsed as a Ruby file.") do |value|
152:         new, old = value.split(/=/, 2)
153: 
154:         unless new and old then
155:           raise OptionParser::InvalidArgument, "Invalid parameter to '-E'"
156:         end
157: 
158:         unless RDoc::Parser.alias_extension old, new then
159:           raise OptionParser::InvalidArgument, "Unknown extension .#{old} to -E"
160:         end
161:       end
162: 
163:       opt.separator nil
164: 
165:       opt.on("--[no-]force-update", "-U",
166:              "Forces rdoc to scan all sources even if",
167:              "newer than the flag file.") do |value|
168:         @force_update = value
169:       end
170: 
171:       opt.separator nil
172: 
173:       opt.on("--pipe",
174:              "Convert RDoc on stdin to HTML") do
175:         @pipe = true
176:       end
177: 
178:       opt.separator nil
179:       opt.separator "Generator Options:"
180:       opt.separator nil
181: 
182:       opt.on("--charset=CHARSET", "-c",
183:              "Specifies the output HTML character-set.") do |value|
184:         @charset = value
185:       end
186: 
187:       opt.separator nil
188: 
189:       generator_text = @generators.keys.map { |name| "  #{name}" }.sort
190: 
191:       opt.on("--fmt=FORMAT", "--format=FORMAT", "-f", @generators.keys,
192:              "Set the output formatter.  One of:", *generator_text) do |value|
193:         @generator_name = value.downcase
194:         setup_generator
195:       end
196: 
197:       opt.separator nil
198: 
199:       opt.on("--include=DIRECTORIES", "-i", Array,
200:              "Set (or add to) the list of directories to",
201:              "be searched when satisfying :include:",
202:              "requests. Can be used more than once.") do |value|
203:         @rdoc_include.concat value.map { |dir| dir.strip }
204:       end
205: 
206:       opt.separator nil
207: 
208:       opt.on("--main=NAME", "-m",
209:              "NAME will be the initial page displayed.") do |value|
210:         @main_page = value
211:       end
212: 
213:       opt.separator nil
214: 
215:       opt.on("--output=DIR", "--op", "-o",
216:              "Set the output directory.") do |value|
217:         @op_dir = value
218:       end
219: 
220:       opt.separator nil
221: 
222:       opt.on("--show-hash", "-H",
223:              "A name of the form #name in a comment is a",
224:              "possible hyperlink to an instance method",
225:              "name. When displayed, the '#' is removed",
226:              "unless this option is specified.") do |value|
227:         @show_hash = value
228:       end
229: 
230:       opt.separator nil
231: 
232:       opt.on("--tab-width=WIDTH", "-w", OptionParser::DecimalInteger,
233:              "Set the width of tab characters.") do |value|
234:         @tab_width = value
235:       end
236: 
237:       opt.separator nil
238: 
239:       opt.on("--template=NAME", "-T",
240:              "Set the template used when generating",
241:              "output.") do |value|
242:         @template = value
243:       end
244: 
245:       opt.separator nil
246: 
247:       opt.on("--title=TITLE", "-t",
248:              "Set TITLE as the title for HTML output.") do |value|
249:         @title = value
250:       end
251: 
252:       opt.separator nil
253: 
254:       opt.on("--webcvs=URL", "-W",
255:              "Specify a URL for linking to a web frontend",
256:              "to CVS. If the URL contains a '\%s', the",
257:              "name of the current file will be",
258:              "substituted; if the URL doesn't contain a",
259:              "'\%s', the filename will be appended to it.") do |value|
260:         @webcvs = value
261:       end
262: 
263:       opt.separator nil
264: 
265:       opt.on("-d", "--diagram", "Prevents -d from tripping --debug")
266: 
267:       opt.separator nil
268:       opt.separator "ri Generator Options:"
269:       opt.separator nil
270: 
271:       opt.on("--ri", "-r",
272:              "Generate output for use by `ri`. The files",
273:              "are stored in the '.rdoc' directory under",
274:              "your home directory unless overridden by a",
275:              "subsequent --op parameter, so no special",
276:              "privileges are needed.") do |value|
277:         @generator_name = "ri"
278:         @op_dir ||= RDoc::RI::Paths::HOMEDIR
279:         setup_generator
280:       end
281: 
282:       opt.separator nil
283: 
284:       opt.on("--ri-site", "-R",
285:              "Generate output for use by `ri`. The files",
286:              "are stored in a site-wide directory,",
287:              "making them accessible to others, so",
288:              "special privileges are needed.") do |value|
289:         @generator_name = "ri"
290:         @op_dir = RDoc::RI::Paths::SITEDIR
291:         setup_generator
292:       end
293: 
294:       opt.separator nil
295:       opt.separator "Generic Options:"
296:       opt.separator nil
297: 
298:       opt.on("-D", "--[no-]debug",
299:              "Displays lots on internal stuff.") do |value|
300:         $DEBUG_RDOC = value
301:       end
302: 
303:       opt.on("--[no-]ignore-invalid",
304:              "Ignore invalid options and continue.") do |value|
305:         ignore_invalid = value
306:       end
307: 
308:       opt.on("--quiet", "-q",
309:              "Don't show progress as we parse.") do |value|
310:         @verbosity = 0
311:       end
312: 
313:       opt.on("--verbose", "-v",
314:              "Display extra progress as we parse.") do |value|
315:         @verbosity = 2
316:       end
317: 
318:       opt.separator nil
319:     end
320: 
321:     argv.insert(0, *ENV['RDOCOPT'].split) if ENV['RDOCOPT']
322:     ignored = []
323: 
324:     begin
325:       opts.parse! argv
326:     rescue OptionParser::InvalidArgument, OptionParser::InvalidOption => e
327:       if ignore_invalid then
328:         ignored << e.args.join(' ')
329:         retry
330:       else
331:         $stderr.puts opts
332:         $stderr.puts
333:         $stderr.puts e
334:         exit 1
335:       end
336:     end
337: 
338:     if @pipe and not argv.empty? then
339:       @pipe = false
340:       ignored << '-p (with files)'
341:     end
342: 
343:     unless ignored.empty? or quiet then
344:       $stderr.puts "invalid options: #{ignored.join ', '}"
345:       $stderr.puts '(invalid options are ignored)'
346:     end
347: 
348:     @op_dir ||= 'doc'
349:     @files = argv.dup
350: 
351:     @rdoc_include << "." if @rdoc_include.empty?
352: 
353:     if @exclude.empty? then
354:       @exclude = nil
355:     else
356:       @exclude = Regexp.new(@exclude.join("|"))
357:     end
358: 
359:     check_files
360: 
361:     # If no template was specified, use the default template for the output
362:     # formatter
363: 
364:     @template ||= @generator_name
365:   end
quiet() click to toggle source

Don’t display progress as we process the files

     # File lib/rdoc/options.rb, line 395
395:   def quiet
396:     @verbosity.zero?
397:   end
quiet=(bool) click to toggle source
     # File lib/rdoc/options.rb, line 399
399:   def quiet=(bool)
400:     @verbosity = bool ? 0 : 1
401:   end
title=(string) click to toggle source

Set the title, but only if not already set. This means that a title set from the command line trumps one set in a source file

     # File lib/rdoc/options.rb, line 388
388:   def title=(string)
389:     @title ||= string
390:   end

Private Instance Methods

check_files() click to toggle source

Check that the files on the command line exist

     # File lib/rdoc/options.rb, line 419
419:   def check_files
420:     @files.each do |f|
421:       stat = File.stat f rescue next
422:       raise RDoc::Error, "file '#{f}' not readable" unless stat.readable?
423:     end
424:   end
setup_generator() click to toggle source

Set up an output generator for the format in @generator_name

     # File lib/rdoc/options.rb, line 408
408:   def setup_generator
409:     @generator = @generators[@generator_name]
410: 
411:     unless @generator then
412:       raise OptionParser::InvalidArgument, "Invalid output formatter"
413:     end
414:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.