Module | RI::Options::OptionList |
In: |
rdoc/ri/ri_options.rb
|
OPTION_LIST | = | [ [ "--help", "-h", nil, "you're looking at it" ], [ "--classes", "-c", nil, "Display the names of classes and modules we\n" + "know about"], [ "--doc-dir", "-d", "<dirname>", "A directory to search for documentation. If not\n"+ "specified, we search the standard rdoc/ri directories."], [ "--format", "-f", "<name>", "Format to use when displaying output:\n" + " " + RI::TextFormatter.list + "\n" + "Use 'bs' (backspace) with most pager programs.\n" + "To use ANSI, either also use the -T option, or\n" + "tell your pager to allow control characters\n" + "(for example using the -R option to less)"], [ "--list-names", "-l", nil, "List all the names known to RDoc, one per line" |
Show an error and exit
# File rdoc/ri/ri_options.rb, line 95 def OptionList.error(msg) $stderr.puts $stderr.puts msg $stderr.puts "\nFor help on options, try 'ri --help'\n\n" exit 1 end
# File rdoc/ri/ri_options.rb, line 75 def OptionList.options OPTION_LIST.map do |long, short, arg,| [ long, short, arg ? GetoptLong::REQUIRED_ARGUMENT : GetoptLong::NO_ARGUMENT ] end end
# File rdoc/ri/ri_options.rb, line 85 def OptionList.strip_output(text) text =~ /^\s+/ leading_spaces = $& text.gsub!(/^#{leading_spaces}/, '') $stdout.puts text end
Show usage and exit
# File rdoc/ri/ri_options.rb, line 104 def OptionList.usage(short_form=false) puts puts(RI::VERSION_STRING) puts name = File.basename($0) OptionList.strip_output("Usage:\n\n\#{name} [options] [names...]\n\nDisplay information on Ruby classes, modules, and methods.\nGive the names of classes or methods to see their documentation.\nPartial names may be given: if the names match more than\none entity, a list will be shown, otherwise details on\nthat entity will be displayed.\n\nNested classes and modules can be specified using the normal\nName::Name notation, and instance methods can be distinguished\nfrom class methods using \".\" (or \"#\") instead of \"::\".\n\nFor example:\n\nri File\nri File.new\nri F.n\nri zip\n\nNote that shell quoting may be required for method names\ncontaining punctuation:\n\nri 'Array.[]'\nri compact\\\\!\n\n") if short_form puts "For help on options, type 'ri -h'" puts "For a list of classes I know about, type 'ri -c'" else puts "Options:\n\n" OPTION_LIST.each do|long, short, arg, desc| opt = sprintf("%15s", "#{long}, #{short}") if arg opt << " " << arg end print opt desc = desc.split("\n") if opt.size < 17 print " "*(18-opt.size) puts desc.shift else puts end desc.each do |line| puts(" "*18 + line) end puts end puts "Options may also be passed in the 'RI' environment variable" exit 0 end end