Exception: OptionParser::ParseError

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ParseError

Returns a new instance of ParseError.



1599
1600
1601
1602
# File 'lib/rubysl/optparse/optparse.rb', line 1599

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



1604
1605
1606
# File 'lib/rubysl/optparse/optparse.rb', line 1604

def args
  @args
end

#reasonObject

Returns error reason. Override this for I18N.



1627
1628
1629
# File 'lib/rubysl/optparse/optparse.rb', line 1627

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

Instance Method Details

#inspectObject



1631
1632
1633
# File 'lib/rubysl/optparse/optparse.rb', line 1631

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

#messageObject Also known as: to_s

Default stringizing method to emit standard error message.



1638
1639
1640
# File 'lib/rubysl/optparse/optparse.rb', line 1638

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

#recover(argv) ⇒ Object

Pushes back erred argument(s) to argv.



1610
1611
1612
1613
# File 'lib/rubysl/optparse/optparse.rb', line 1610

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

#set_option(opt, eq) ⇒ Object



1615
1616
1617
1618
1619
1620
1621
1622
# File 'lib/rubysl/optparse/optparse.rb', line 1615

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