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'
DIR =
File.join(__dir__, '')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

:nodoc:



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

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

Instance Attribute Details

#additionalObject

Returns the value of attribute additional.



2270
2271
2272
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2270

def additional
  @additional
end

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

#reasonObject

Returns error reason. Override this for I18N.



2304
2305
2306
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2304

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

Class Method Details

.filter_backtrace(array) ⇒ Object



2281
2282
2283
2284
2285
2286
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2281

def self.filter_backtrace(array)
  unless $DEBUG
    array.delete_if {|bt| bt.start_with?(DIR)}
  end
  array
end

Instance Method Details

#inspectObject



2308
2309
2310
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2308

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

#messageObject Also known as: to_s

Default stringizing method to emit standard error message.



2315
2316
2317
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2315

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

#recover(argv) ⇒ Object

Pushes back erred argument(s) to argv.



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

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

#set_backtrace(array) ⇒ Object



2288
2289
2290
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2288

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

#set_option(opt, eq) ⇒ Object



2292
2293
2294
2295
2296
2297
2298
2299
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2292

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