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


1755
1756
1757
1758
# File 'lib/optparse.rb', line 1755

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args


1760
1761
1762
# File 'lib/optparse.rb', line 1760

def args
  @args
end

#reasonObject

Returns error reason. Override this for I18N.


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

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

Class Method Details

.filter_backtrace(array) ⇒ Object


1771
1772
1773
1774
1775
1776
# File 'lib/optparse.rb', line 1771

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

Instance Method Details

#inspectObject


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

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

#messageObject Also known as: to_s

Default stringizing method to emit standard error message.


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

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

#recover(argv) ⇒ Object

Pushes back erred argument(s) to argv.


1766
1767
1768
1769
# File 'lib/optparse.rb', line 1766

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

#set_backtrace(array) ⇒ Object


1778
1779
1780
# File 'lib/optparse.rb', line 1778

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

#set_option(opt, eq) ⇒ Object


1782
1783
1784
1785
1786
1787
1788
1789
# File 'lib/optparse.rb', line 1782

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