Module: RI::Options::OptionList

Defined in:
lib/rdoc/ri/ri_options.rb

Constant Summary collapse

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"
  ],

  [ "--no-pager",      "-T",   nil,
    "Send output directly to stdout." 
  ],

  [ "--width",         "-w",   "output width",
  "Set the width of the output" ],

  [ "--version",       "-v",   nil,
   "Display the version of ri"
  ],

]

Class Method Summary collapse

Class Method Details

.error(msg) ⇒ Object

Show an error and exit



117
118
119
120
121
122
123
# File 'lib/rdoc/ri/ri_options.rb', line 117

def OptionList.error(msg)
  $stderr.puts
  $stderr.puts msg
  name = File.basename $PROGRAM_NAME
  $stderr.puts "\nFor help on options, try '#{name} --help'\n\n"
  exit 1
end

.optionsObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/rdoc/ri/ri_options.rb', line 95

def OptionList.options
  OPTION_LIST.map do |long, short, arg,|
    option = []
    option << long
    option << short unless short.nil?
    option << (arg ? GetoptLong::REQUIRED_ARGUMENT :
                     GetoptLong::NO_ARGUMENT)
    option
  end
end

.strip_output(text) ⇒ Object



107
108
109
110
111
112
# File 'lib/rdoc/ri/ri_options.rb', line 107

def OptionList.strip_output(text)
  text =~ /^\s+/
  leading_spaces = $&
  text.gsub!(/^#{leading_spaces}/, '')
  $stdout.puts text
end

.usage(short_form = false) ⇒ Object

Show usage and exit



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/rdoc/ri/ri_options.rb', line 127

def OptionList.usage(short_form=false)
  
  puts
  puts(RI::VERSION_STRING)
  puts
  
  name = File.basename($0)

  directories = [
    RI::Paths::SYSDIR,
    RI::Paths::SITEDIR,
    RI::Paths::HOMEDIR
  ]

  if RI::Paths::GEMDIRS then
    Gem.path.each do |dir|
      directories << "#{dir}/doc/*/ri"
    end
  end

  directories = directories.join("\n    ")

  OptionList.strip_output(<<-EOT)
    Usage:

      #{name} [options]  [names...]

    Display information on Ruby classes, modules, and methods.
    Give the names of classes or methods to see their documentation.
    Partial names may be given: if the names match more than
    one entity, a list will be shown, otherwise details on
    that entity will be displayed.

    Nested classes and modules can be specified using the normal
    Name::Name notation, and instance methods can be distinguished
    from class methods using "." (or "#") instead of "::".

    For example:

        #{name}  File
        #{name}  File.new
        #{name}  F.n
        #{name}  zip

    Note that shell quoting may be required for method names
    containing punctuation:

        #{name} 'Array.[]'
        #{name} compact\\!

    By default ri searches for documentation in the following
    directories:

        #{directories}

    Specifying the --system, --site, --home, --gems or --doc-dir
    options will limit ri to searching only the specified
    directories.

  EOT

  if short_form
    puts "For help on options, type '#{name} -h'"
    puts "For a list of classes I know about, type '#{name} -c'"
  else
    puts "Options:\n\n"
    OPTION_LIST.each do|long, short, arg, desc|
      opt = ''
      opt << (short ? sprintf("%15s", "#{long}, #{short}") :
                      sprintf("%15s", long))
      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