| Class | Options |
| In: |
lib/rdoc/options.rb
|
| Parent: | Object |
| all_one_file | [R] | should the output be placed into a single file |
| charset | [R] | character-set |
| css | [R] | URL of stylesheet |
| diagram | [R] | should diagrams be drawn |
| exclude | [RW] | files matching this pattern will be excluded |
| extra_accessor_flags | [R] | |
| extra_accessors | [R] | pattern for additional attr_… style methods |
| fileboxes | [R] | should we draw fileboxes in diagrams |
| files | [R] | and the list of files to be processed |
| generator | [RW] | description of the output generator (set with the -fmt option |
| image_format | [R] | image format for diagrams |
| include_line_numbers | [R] | include line numbers in the source listings |
| inline_source | [R] | should source code be included inline, or displayed in a popup |
| 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) |
| merge | [R] | merge into classes of the name name when generating ri |
| op_dir | [RW] | the name of the output directory |
| op_name | [R] | the name to use for the output |
| promiscuous | [R] | Are we promiscuous about showing module contents across multiple files |
| quiet | [R] | Don‘t display progress as we process the files |
| rdoc_include | [R] | array of directories to search for files to satisfy an :include: |
| show_all | [RW] | include private and protected methods in the output |
| 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 |
| webcvs | [R] | URL of web cvs frontend |
Parse command line options. We‘re passed a hash containing output generators, keyed by the generator name
# File lib/rdoc/options.rb, line 342
342: def parse(argv, generators)
343: old_argv = ARGV.dup
344: begin
345: ARGV.replace(argv)
346: @op_dir = "doc"
347: @op_name = nil
348: @show_all = false
349: @main_page = nil
350: @marge = false
351: @exclude = []
352: @quiet = false
353: @generator_name = 'html'
354: @generator = generators[@generator_name]
355: @rdoc_include = []
356: @title = nil
357: @template = nil
358: @diagram = false
359: @fileboxes = false
360: @show_hash = false
361: @image_format = 'png'
362: @inline_source = false
363: @all_one_file = false
364: @tab_width = 8
365: @include_line_numbers = false
366: @extra_accessor_flags = {}
367: @promiscuous = false
368:
369: @css = nil
370: @webcvs = nil
371:
372: @charset = case $KCODE
373: when /^S/i
374: 'Shift_JIS'
375: when /^E/i
376: 'EUC-JP'
377: else
378: 'iso-8859-1'
379: end
380:
381: accessors = []
382:
383: go = GetoptLong.new(*OptionList.options)
384: go.quiet = true
385:
386: go.each do |opt, arg|
387: case opt
388: when "--all" then @show_all = true
389: when "--charset" then @charset = arg
390: when "--debug" then $DEBUG = true
391: when "--exclude" then @exclude << Regexp.new(arg)
392: when "--inline-source" then @inline_source = true
393: when "--line-numbers" then @include_line_numbers = true
394: when "--main" then @main_page = arg
395: when "--merge" then @merge = true
396: when "--one-file" then @all_one_file = @inline_source = true
397: when "--op" then @op_dir = arg
398: when "--opname" then @op_name = arg
399: when "--promiscuous" then @promiscuous = true
400: when "--quiet" then @quiet = true
401: when "--show-hash" then @show_hash = true
402: when "--style" then @css = arg
403: when "--template" then @template = arg
404: when "--title" then @title = arg
405: when "--webcvs" then @webcvs = arg
406:
407: when "--accessor"
408: arg.split(/,/).each do |accessor|
409: if accessor =~ /^(\w+)(=(.*))?$/
410: accessors << $1
411: @extra_accessor_flags[$1] = $3
412: end
413: end
414:
415: when "--diagram"
416: check_diagram
417: @diagram = true
418:
419: when "--fileboxes"
420: @fileboxes = true if @diagram
421:
422: when "--fmt"
423: @generator_name = arg.downcase
424: setup_generator(generators)
425:
426: when "--help"
427: OptionList.usage(generators.keys)
428:
429: when "--help-output"
430: OptionList.help_output
431:
432: when "--image-format"
433: if ['gif', 'png', 'jpeg', 'jpg'].include?(arg)
434: @image_format = arg
435: else
436: raise GetoptLong::InvalidOption.new("unknown image format: #{arg}")
437: end
438:
439: when "--include"
440: @rdoc_include.concat arg.split(/\s*,\s*/)
441:
442: when "--ri", "--ri-site", "--ri-system"
443: @generator_name = "ri"
444: @op_dir = case opt
445: when "--ri" then RI::Paths::HOMEDIR
446: when "--ri-site" then RI::Paths::SITEDIR
447: when "--ri-system" then RI::Paths::SYSDIR
448: else fail opt
449: end
450: setup_generator(generators)
451:
452: when "--tab-width"
453: begin
454: @tab_width = Integer(arg)
455: rescue
456: $stderr.puts "Invalid tab width: '#{arg}'"
457: exit 1
458: end
459:
460: when "--extension"
461: new, old = arg.split(/=/, 2)
462: OptionList.error("Invalid parameter to '-E'") unless new && old
463: unless RDoc::ParserFactory.alias_extension(old, new)
464: OptionList.error("Unknown extension .#{old} to -E")
465: end
466:
467: when "--version"
468: puts VERSION_STRING
469: exit
470: end
471:
472: end
473:
474: @files = ARGV.dup
475:
476: @rdoc_include << "." if @rdoc_include.empty?
477:
478: if @exclude.empty?
479: @exclude = nil
480: else
481: @exclude = Regexp.new(@exclude.join("|"))
482: end
483:
484: check_files
485:
486: # If no template was specified, use the default
487: # template for the output formatter
488:
489: @template ||= @generator_name
490:
491: # Generate a regexp from the accessors
492: unless accessors.empty?
493: re = '^(' + accessors.map{|a| Regexp.quote(a)}.join('|') + ')$'
494: @extra_accessors = Regexp.new(re)
495: end
496:
497: rescue GetoptLong::InvalidOption, GetoptLong::MissingArgument => error
498: OptionList.error(error.message)
499:
500: ensure
501: ARGV.replace(old_argv)
502: end
503: end
Check that the right version of ‘dot’ is available. Unfortuately this doesn‘t work correctly under Windows NT, so we‘ll bypass the test under Windows
# File lib/rdoc/options.rb, line 537
537: def check_diagram
538: return if RUBY_PLATFORM =~ /win/
539:
540: ok = false
541: ver = nil
542: IO.popen("dot -V 2>&1") do |io|
543: ver = io.read
544: if ver =~ /dot\s+version(?:\s+gviz)?\s+(\d+)\.(\d+)/
545: ok = ($1.to_i > 1) || ($1.to_i == 1 && $2.to_i >= 8)
546: end
547: end
548: unless ok
549: if ver =~ /^dot version/
550: $stderr.puts "Warning: You may need dot V1.8.6 or later to use\n",
551: "the --diagram option correctly. You have:\n\n ",
552: ver,
553: "\nDiagrams might have strange background colors.\n\n"
554: else
555: $stderr.puts "You need the 'dot' program to produce diagrams.",
556: "(see http://www.research.att.com/sw/tools/graphviz/)\n\n"
557: exit
558: end
559: # exit
560: end
561: end
Check that the files on the command line exist
# File lib/rdoc/options.rb, line 565
565: def check_files
566: @files.each do |f|
567: stat = File.stat f rescue error("File not found: #{f}")
568: error("File '#{f}' not readable") unless stat.readable?
569: end
570: end
# File lib/rdoc/options.rb, line 572
572: def error(str)
573: $stderr.puts str
574: exit(1)
575: end
Set up an output generator for the format in @generator_name
# File lib/rdoc/options.rb, line 521
521: def setup_generator(generators)
522: @generator = generators[@generator_name]
523: if !@generator
524: OptionList.error("Invalid output formatter")
525: end
526:
527: if @generator_name == "xml"
528: @all_one_file = true
529: @inline_source = true
530: end
531: end