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 |
force_update | [R] | scan newer sources than the flag file if true. |
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 349 349: def parse(argv, generators) 350: old_argv = ARGV.dup 351: begin 352: ARGV.replace(argv) 353: @op_dir = "doc" 354: @op_name = nil 355: @show_all = false 356: @main_page = nil 357: @marge = false 358: @exclude = [] 359: @quiet = false 360: @generator_name = 'html' 361: @generator = generators[@generator_name] 362: @rdoc_include = [] 363: @title = nil 364: @template = nil 365: @diagram = false 366: @fileboxes = false 367: @show_hash = false 368: @image_format = 'png' 369: @inline_source = false 370: @all_one_file = false 371: @tab_width = 8 372: @include_line_numbers = false 373: @extra_accessor_flags = {} 374: @promiscuous = false 375: @force_update = false 376: 377: @css = nil 378: @webcvs = nil 379: 380: @charset = case $KCODE 381: when /^S/i 382: 'Shift_JIS' 383: when /^E/i 384: 'EUC-JP' 385: else 386: 'iso-8859-1' 387: end 388: 389: accessors = [] 390: 391: go = GetoptLong.new(*OptionList.options) 392: go.quiet = true 393: 394: go.each do |opt, arg| 395: case opt 396: when "--all" then @show_all = true 397: when "--charset" then @charset = arg 398: when "--debug" then $DEBUG = true 399: when "--exclude" then @exclude << Regexp.new(arg) 400: when "--inline-source" then @inline_source = true 401: when "--line-numbers" then @include_line_numbers = true 402: when "--main" then @main_page = arg 403: when "--merge" then @merge = true 404: when "--one-file" then @all_one_file = @inline_source = true 405: when "--op" then @op_dir = arg 406: when "--opname" then @op_name = arg 407: when "--promiscuous" then @promiscuous = true 408: when "--quiet" then @quiet = true 409: when "--show-hash" then @show_hash = true 410: when "--style" then @css = arg 411: when "--template" then @template = arg 412: when "--title" then @title = arg 413: when "--webcvs" then @webcvs = arg 414: 415: when "--accessor" 416: arg.split(/,/).each do |accessor| 417: if accessor =~ /^(\w+)(=(.*))?$/ 418: accessors << $1 419: @extra_accessor_flags[$1] = $3 420: end 421: end 422: 423: when "--diagram" 424: check_diagram 425: @diagram = true 426: 427: when "--fileboxes" 428: @fileboxes = true if @diagram 429: 430: when "--fmt" 431: @generator_name = arg.downcase 432: setup_generator(generators) 433: 434: when "--help" 435: OptionList.usage(generators.keys) 436: 437: when "--help-output" 438: OptionList.help_output 439: 440: when "--image-format" 441: if ['gif', 'png', 'jpeg', 'jpg'].include?(arg) 442: @image_format = arg 443: else 444: raise GetoptLong::InvalidOption.new("unknown image format: #{arg}") 445: end 446: 447: when "--include" 448: @rdoc_include.concat arg.split(/\s*,\s*/) 449: 450: when "--ri", "--ri-site", "--ri-system" 451: @generator_name = "ri" 452: @op_dir = case opt 453: when "--ri" then RI::Paths::HOMEDIR 454: when "--ri-site" then RI::Paths::SITEDIR 455: when "--ri-system" then RI::Paths::SYSDIR 456: else fail opt 457: end 458: setup_generator(generators) 459: 460: when "--tab-width" 461: begin 462: @tab_width = Integer(arg) 463: rescue 464: $stderr.puts "Invalid tab width: '#{arg}'" 465: exit 1 466: end 467: 468: when "--extension" 469: new, old = arg.split(/=/, 2) 470: OptionList.error("Invalid parameter to '-E'") unless new && old 471: unless RDoc::ParserFactory.alias_extension(old, new) 472: OptionList.error("Unknown extension .#{old} to -E") 473: end 474: 475: when "--force-update" 476: @force_update = true 477: 478: when "--version" 479: puts VERSION_STRING 480: exit 481: end 482: 483: end 484: 485: @files = ARGV.dup 486: 487: @rdoc_include << "." if @rdoc_include.empty? 488: 489: if @exclude.empty? 490: @exclude = nil 491: else 492: @exclude = Regexp.new(@exclude.join("|")) 493: end 494: 495: check_files 496: 497: # If no template was specified, use the default 498: # template for the output formatter 499: 500: @template ||= @generator_name 501: 502: # Generate a regexp from the accessors 503: unless accessors.empty? 504: re = '^(' + accessors.map{|a| Regexp.quote(a)}.join('|') + ')$' 505: @extra_accessors = Regexp.new(re) 506: end 507: 508: rescue GetoptLong::InvalidOption, GetoptLong::MissingArgument => error 509: OptionList.error(error.message) 510: 511: ensure 512: ARGV.replace(old_argv) 513: end 514: 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 548 548: def check_diagram 549: return if RUBY_PLATFORM =~ /mswin|cygwin|mingw|bccwin/ 550: 551: ok = false 552: ver = nil 553: IO.popen("dot -V 2>&1") do |io| 554: ver = io.read 555: if ver =~ /dot.+version(?:\s+gviz)?\s+(\d+)\.(\d+)/ 556: ok = ($1.to_i > 1) || ($1.to_i == 1 && $2.to_i >= 8) 557: end 558: end 559: unless ok 560: if ver =~ /^dot.+version/ 561: $stderr.puts "Warning: You may need dot V1.8.6 or later to use\n", 562: "the --diagram option correctly. You have:\n\n ", 563: ver, 564: "\nDiagrams might have strange background colors.\n\n" 565: else 566: $stderr.puts "You need the 'dot' program to produce diagrams.", 567: "(see http://www.research.att.com/sw/tools/graphviz/)\n\n" 568: exit 569: end 570: # exit 571: end 572: end
Check that the files on the command line exist
# File lib/rdoc/options.rb, line 576 576: def check_files 577: @files.each do |f| 578: stat = File.stat f rescue error("File not found: #{f}") 579: error("File '#{f}' not readable") unless stat.readable? 580: end 581: end
# File lib/rdoc/options.rb, line 583 583: def error(str) 584: $stderr.puts str 585: exit(1) 586: end
Set up an output generator for the format in @generator_name
# File lib/rdoc/options.rb, line 532 532: def setup_generator(generators) 533: @generator = generators[@generator_name] 534: if !@generator 535: OptionList.error("Invalid output formatter") 536: end 537: 538: if @generator_name == "xml" 539: @all_one_file = true 540: @inline_source = true 541: end 542: end