Exception: OptionParser::ParseError

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

Overview

Base class of exceptions from OptionParser.

Constant Summary collapse

Reason =

Reason which caused the error.

'parse error'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ParseError

Returns a new instance of ParseError


1794
1795
1796
1797
# File 'lib/optparse.rb', line 1794

def initialize(*args)
  @args = args
  @reason = nil
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args


1799
1800
1801
# File 'lib/optparse.rb', line 1799

def args
  @args
end

#reasonObject

Returns error reason. Override this for I18N.


1833
1834
1835
# File 'lib/optparse.rb', line 1833

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

Class Method Details

.filter_backtrace(array) ⇒ Object


1810
1811
1812
1813
1814
1815
# File 'lib/optparse.rb', line 1810

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

Instance Method Details

#inspectObject


1837
1838
1839
# File 'lib/optparse.rb', line 1837

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

#messageObject Also known as: to_s

Default stringizing method to emit standard error message.


1844
1845
1846
# File 'lib/optparse.rb', line 1844

def message
  reason + ': ' + args.join(' ')
end

#recover(argv) ⇒ Object

Pushes back erred argument(s) to argv.


1805
1806
1807
1808
# File 'lib/optparse.rb', line 1805

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

#set_backtrace(array) ⇒ Object


1817
1818
1819
# File 'lib/optparse.rb', line 1817

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

#set_option(opt, eq) ⇒ Object


1821
1822
1823
1824
1825
1826
1827
1828
# File 'lib/optparse.rb', line 1821

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