Exception: Gem::OptionParser::ParseError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/rubygems/vendor/optparse/lib/optparse.rb

Overview

Base class of exceptions from Gem::OptionParser.

Constant Summary collapse

Reason =

Reason which caused the error.

'parse error'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, additional: nil) ⇒ ParseError

:nodoc:



2221
2222
2223
2224
2225
2226
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2221

def initialize(*args, additional: nil)
  @additional = additional
  @arg0, = args
  @args = args
  @reason = nil
end

Instance Attribute Details

#additionalObject

Returns the value of attribute additional.



2230
2231
2232
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2230

def additional
  @additional
end

#argsObject (readonly)

Returns the value of attribute args.



2228
2229
2230
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2228

def args
  @args
end

#reasonObject

Returns error reason. Override this for I18N.



2263
2264
2265
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2263

def reason
  @reason || self.class::Reason
end

Class Method Details

.filter_backtrace(array) ⇒ Object



2240
2241
2242
2243
2244
2245
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2240

def self.filter_backtrace(array)
  unless $DEBUG
    array.delete_if(&%r"\A#{Regexp.quote(__FILE__)}:"o.method(:=~))
  end
  array
end

Instance Method Details

#inspectObject



2267
2268
2269
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2267

def inspect
  "#<#{self.class}: #{args.join(' ')}>"
end

#messageObject Also known as: to_s

Default stringizing method to emit standard error message.



2274
2275
2276
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2274

def message
  "#{reason}: #{args.join(' ')}#{additional[@arg0] if additional}"
end

#recover(argv) ⇒ Object

Pushes back erred argument(s) to argv.



2235
2236
2237
2238
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2235

def recover(argv)
  argv[0, 0] = @args
  argv
end

#set_backtrace(array) ⇒ Object



2247
2248
2249
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2247

def set_backtrace(array)
  super(self.class.filter_backtrace(array))
end

#set_option(opt, eq) ⇒ Object



2251
2252
2253
2254
2255
2256
2257
2258
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2251

def set_option(opt, eq)
  if eq
    @args[0] = opt
  else
    @args.unshift(opt)
  end
  self
end