| Module | RI::Options::OptionList |
| In: |
lib/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.\n" + "May be repeated."], [ "--system", nil, nil, "Include documentation from Ruby's standard library:\n " + RI::Paths::SYSDIR ], [ "--site", nil, nil, "Include documentation from libraries installed in site_lib:\n " + RI::Paths::SITEDIR ], [ "--home", nil, nil, "Include documentation stored in ~/.rdoc:\n " + (RI::Paths::HOMEDIR || "No ~/.rdoc found") ], [ "--gems", nil, nil, "Include documentation from RubyGems:\n" + (RI::Paths::GEMDIRS ? Gem.path.map { |dir| " #{dir}/doc/*/ri" }.join("\n") : "No Rubygems ri found.") ], [ "--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 lib/rdoc/ri/ri_options.rb, line 95
95: def OptionList.options
96: OPTION_LIST.map do |long, short, arg,|
97: option = []
98: option << long
99: option << short unless short.nil?
100: option << (arg ? GetoptLong::REQUIRED_ARGUMENT :
101: GetoptLong::NO_ARGUMENT)
102: option
103: end
104: end
# File lib/rdoc/ri/ri_options.rb, line 107
107: def OptionList.strip_output(text)
108: text =~ /^\s+/
109: leading_spaces = $&
110: text.gsub!(/^#{leading_spaces}/, '')
111: $stdout.puts text
112: end
Show usage and exit
# File lib/rdoc/ri/ri_options.rb, line 127
127: def OptionList.usage(short_form=false)
128:
129: puts
130: puts(RI::VERSION_STRING)
131: puts
132:
133: name = File.basename($0)
134:
135: directories = [
136: RI::Paths::SYSDIR,
137: RI::Paths::SITEDIR,
138: RI::Paths::HOMEDIR
139: ]
140:
141: if RI::Paths::GEMDIRS then
142: Gem.path.each do |dir|
143: directories << "#{dir}/doc/*/ri"
144: end
145: end
146:
147: directories = directories.join("\n ")
148:
149: 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\n\#{name} File\n\#{name} File.new\n\#{name} F.n\n\#{name} zip\n\nNote that shell quoting may be required for method names\ncontaining punctuation:\n\n\#{name} 'Array.[]'\n\#{name} compact\\\\!\n\nBy default ri searches for documentation in the following\ndirectories:\n\n\#{directories}\n\nSpecifying the --system, --site, --home, --gems or --doc-dir\noptions will limit ri to searching only the specified\ndirectories.\n\n")
150:
151: if short_form
152: puts "For help on options, type '#{name} -h'"
153: puts "For a list of classes I know about, type '#{name} -c'"
154: else
155: puts "Options:\n\n"
156: OPTION_LIST.each do|long, short, arg, desc|
157: opt = ''
158: opt << (short ? sprintf("%15s", "#{long}, #{short}") :
159: sprintf("%15s", long))
160: if arg
161: opt << " " << arg
162: end
163: print opt
164: desc = desc.split("\n")
165: if opt.size < 17
166: print " "*(18-opt.size)
167: puts desc.shift
168: else
169: puts
170: end
171: desc.each do |line|
172: puts(" "*18 + line)
173: end
174: puts
175: end
176: puts "Options may also be passed in the 'RI' environment variable"
177: exit 0
178: end
179: end