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

Returns a new instance of ParseError.



2126
2127
2128
2129
2130
2131
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2126

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

Instance Attribute Details

#additionalObject

Returns the value of attribute additional.



2135
2136
2137
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2135

def additional
  @additional
end

#argsObject (readonly)

Returns the value of attribute args.



2133
2134
2135
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2133

def args
  @args
end

#reasonObject

Returns error reason. Override this for I18N.



2168
2169
2170
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2168

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

Class Method Details

.filter_backtrace(array) ⇒ Object



2145
2146
2147
2148
2149
2150
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2145

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

Instance Method Details

#inspectObject



2172
2173
2174
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2172

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

#messageObject Also known as: to_s

Default stringizing method to emit standard error message.



2179
2180
2181
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2179

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

#recover(argv) ⇒ Object

Pushes back erred argument(s) to argv.



2140
2141
2142
2143
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2140

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

#set_backtrace(array) ⇒ Object



2152
2153
2154
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2152

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

#set_option(opt, eq) ⇒ Object



2156
2157
2158
2159
2160
2161
2162
2163
# File 'lib/rubygems/vendor/optparse/lib/optparse.rb', line 2156

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