class RDoc::RI::Driver

def self.process_args argv

def self.process_args argv
  options = default_options
  opts = OptionParser.new do |opt|
    opt.program_name = File.basename $0
    opt.version = RDoc::VERSION
    opt.release = nil
    opt.summary_indent = ' ' * 4
    opt.banner = <<-EOT
age: #{opt.program_name} [options] [name ...]
ere name can be:
Class | Module | Module::Class
Class::method | Class#method | Class.method | method
gem_name: | gem_name:README | gem_name:History
ruby: | ruby:NEWS | ruby:globals
l class names may be abbreviated to their minimum unambiguous form.
 a name is ambiguous, all valid options will be listed.
'.' matches either class or instance methods, while #method
tches only instance and ::method matches only class methods.
ADME and other files may be displayed by prefixing them with the gem name
ey're contained in.  If the gem name is followed by a ':' all files in the
m will be shown.  The file name extension may be omitted where it is
ambiguous.
uby' can be used as a pseudo gem name to display files from the Ruby
re documentation. Use 'ruby:' by itself to get a list of all available
re documentation files.
r example:
  #{opt.program_name} Fil
  #{opt.program_name} File
  #{opt.program_name} File.new
  #{opt.program_name} zip
  #{opt.program_name} rdoc:README
  #{opt.program_name} ruby:comments
te that shell quoting or escaping may be required for method names
ntaining punctuation:
  #{opt.program_name} 'Array.[]'
  #{opt.program_name} compact\\!
 see the default directories #{opt.program_name} will search, run:
  #{opt.program_name} --list-doc-dirs
ecifying the --system, --site, --home, --gems, or --doc-dir options
ll limit ri to searching only the specified directories.
 options may be set in the RI environment variable.
e ri pager can be set with the RI_PAGER environment variable
 the PAGER environment variable.
    EOT
    opt.separator nil
    opt.separator "Options:"
    opt.separator nil
    opt.on("--[no-]interactive", "-i",
           "In interactive mode you can repeatedly",
           "look up methods with autocomplete.") do |interactive|
      options[:interactive] = interactive
    end
    opt.separator nil
    opt.on("--[no-]all", "-a",
           "Show all documentation for a class or",
           "module.") do |show_all|
      options[:show_all] = show_all
    end
    opt.separator nil
    opt.on("--[no-]list", "-l",
           "List classes ri knows about.") do |list|
      options[:list] = list
    end
    opt.separator nil
    opt.on("--[no-]pager",
           "Send output to a pager,",
           "rather than directly to stdout.") do |use_pager|
      options[:use_stdout] = !use_pager
    end
    opt.separator nil
    opt.on("-T",
           "Synonym for --no-pager.") do
      options[:use_stdout] = true
    end
    opt.separator nil
    opt.on("--width=WIDTH", "-w", OptionParser::DecimalInteger,
           "Set the width of the output.") do |width|
      options[:width] = width
    end
    opt.separator nil
    opt.on("--server[=PORT]", Integer,
           "Run RDoc server on the given port.",
           "The default port is 8214.") do |port|
      options[:server] = port || 8214
    end
    opt.separator nil
    formatters = RDoc::Markup.constants.grep(/^To[A-Z][a-z]+$/).sort
    formatters = formatters.sort.map do |formatter|
      formatter.to_s.sub('To', '').downcase
    end
    formatters -= %w[html label test] # remove useless output formats
    opt.on("--format=NAME", "-f",
           "Use the selected formatter.  The default",
           "formatter is bs for paged output and ansi",
           "otherwise.  Valid formatters are:",
           "#{formatters.join(', ')}.", formatters) do |value|
      options[:formatter] = RDoc::Markup.const_get "To#{value.capitalize}"
    end
    opt.separator nil
    opt.on("--[no-]expand-refs", "Expand rdoc-refs at the end of output") do |value|
      options[:expand_refs] = value
    end
    opt.separator nil
    opt.on("--help", "-h",
           "Show help and exit.") do
      puts opts
      exit
    end
    opt.separator nil
    opt.on("--version", "-v",
           "Output version information and exit.") do
      puts "#{opts.program_name} #{opts.version}"
      exit
    end
    opt.separator nil
    opt.separator "Data source options:"
    opt.separator nil
    opt.on("--[no-]list-doc-dirs",
           "List the directories from which ri will",
           "source documentation on stdout and exit.") do |list_doc_dirs|
      options[:list_doc_dirs] = list_doc_dirs
    end
    opt.separator nil
    opt.on("--doc-dir=DIRNAME", "-d", Array,
           "List of directories from which to source",
           "documentation in addition to the standard",
           "directories.  May be repeated.") do |value|
      value.each do |dir|
        unless File.directory? dir then
          raise OptionParser::InvalidArgument, "#{dir} is not a directory"
        end
        options[:extra_doc_dirs] << File.expand_path(dir)
      end
    end
    opt.separator nil
    opt.on("--no-standard-docs",
           "Do not include documentation from",
           "the Ruby standard library, site_lib,",
           "installed gems, or ~/.rdoc.",
           "Use with --doc-dir.") do
      options[:use_system] = false
      options[:use_site] = false
      options[:use_gems] = false
      options[:use_home] = false
    end
    opt.separator nil
    opt.on("--[no-]system",
           "Include documentation from Ruby's",
           "standard library.  Defaults to true.") do |value|
      options[:use_system] = value
    end
    opt.separator nil
    opt.on("--[no-]site",
           "Include documentation from libraries",
           "installed in site_lib.",
           "Defaults to true.") do |value|
      options[:use_site] = value
    end
    opt.separator nil
    opt.on("--[no-]gems",
           "Include documentation from RubyGems.",
           "Defaults to true.") do |value|
      options[:use_gems] = value
    end
    opt.separator nil
    opt.on("--[no-]home",
           "Include documentation stored in ~/.rdoc.",
           "Defaults to true.") do |value|
      options[:use_home] = value
    end
    opt.separator nil
    opt.separator "Debug options:"
    opt.separator nil
    opt.on("--[no-]profile",
           "Run with the ruby profiler.") do |value|
      options[:profile] = value
    end
    opt.separator nil
    opt.on("--dump=CACHE",
           "Dump data from an ri cache or data file.") do |value|
      unless File.readable?(value)
        abort "#{value.inspect} is not readable"
      end
      if File.directory?(value)
        abort "#{value.inspect} is a directory"
      end
      options[:dump_path] = File.new(value)
    end
  end
  argv = ENV['RI'].to_s.split(' ').concat argv
  opts.parse! argv
  options[:names] = argv
  options[:use_stdout] ||= !$stdout.tty?
  options[:use_stdout] ||= options[:interactive]
  options[:width] ||= 72
  options
rescue OptionParser::InvalidArgument, OptionParser::InvalidOption => e
  puts opts
  puts
  puts e
  exit 1
end