Module | RI::Options::OptionList |
In: |
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" |
# File ri/ri_options.rb, line 75 75: def OptionList.options 76: OPTION_LIST.map do |long, short, arg,| 77: [ long, 78: short, 79: arg ? GetoptLong::REQUIRED_ARGUMENT : GetoptLong::NO_ARGUMENT 80: ] 81: end 82: end
# File ri/ri_options.rb, line 85 85: def OptionList.strip_output(text) 86: text =~ /^\s+/ 87: leading_spaces = $& 88: text.gsub!(/^#{leading_spaces}/, '') 89: $stdout.puts text 90: end
Show usage and exit
# File ri/ri_options.rb, line 104 104: def OptionList.usage(short_form=false) 105: 106: puts 107: puts(RI::VERSION_STRING) 108: puts 109: 110: name = File.basename($0) 111: 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") 112: 113: if short_form 114: puts "For help on options, type 'ri -h'" 115: puts "For a list of classes I know about, type 'ri -c'" 116: else 117: puts "Options:\n\n" 118: OPTION_LIST.each do|long, short, arg, desc| 119: opt = sprintf("%15s", "#{long}, #{short}") 120: if arg 121: opt << " " << arg 122: end 123: print opt 124: desc = desc.split("\n") 125: if opt.size < 17 126: print " "*(18-opt.size) 127: puts desc.shift 128: else 129: puts 130: end 131: desc.each do |line| 132: puts(" "*18 + line) 133: end 134: puts 135: end 136: puts "Options may also be passed in the 'RI' environment variable" 137: exit 0 138: end 139: end