Exception: Gem::OptionParser::ParseError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/rubygems/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.



2104
2105
2106
2107
2108
2109
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2104

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

Instance Attribute Details

#additionalObject

Returns the value of attribute additional.



2113
2114
2115
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2113

def additional
  @additional
end

#argsObject (readonly)

Returns the value of attribute args.



2111
2112
2113
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2111

def args
  @args
end

#reasonObject

Returns error reason. Override this for I18N.



2146
2147
2148
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2146

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

Class Method Details

.filter_backtrace(array) ⇒ Object



2123
2124
2125
2126
2127
2128
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2123

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

Instance Method Details

#inspectObject



2150
2151
2152
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2150

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

#messageObject Also known as: to_s

Default stringizing method to emit standard error message.



2157
2158
2159
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2157

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

#recover(argv) ⇒ Object

Pushes back erred argument(s) to argv.



2118
2119
2120
2121
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2118

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

#set_backtrace(array) ⇒ Object



2130
2131
2132
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2130

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

#set_option(opt, eq) ⇒ Object



2134
2135
2136
2137
2138
2139
2140
2141
# File 'lib/rubygems/optparse/lib/optparse.rb', line 2134

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