Exception: OptionParser::ParseError

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



1990
1991
1992
1993
# File 'lib/MrMurano/optparse.rb', line 1990

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



1995
1996
1997
# File 'lib/MrMurano/optparse.rb', line 1995

def args
  @args
end

#reasonObject

Returns error reason. Override this for I18N.



2029
2030
2031
# File 'lib/MrMurano/optparse.rb', line 2029

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

Class Method Details

.filter_backtrace(array) ⇒ Object



2006
2007
2008
2009
2010
2011
# File 'lib/MrMurano/optparse.rb', line 2006

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

Instance Method Details

#inspectObject



2033
2034
2035
# File 'lib/MrMurano/optparse.rb', line 2033

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

#messageObject Also known as: to_s

Default stringizing method to emit standard error message.



2040
2041
2042
# File 'lib/MrMurano/optparse.rb', line 2040

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

#recover(argv) ⇒ Object

Pushes back erred argument(s) to argv.



2001
2002
2003
2004
# File 'lib/MrMurano/optparse.rb', line 2001

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

#set_backtrace(array) ⇒ Object



2013
2014
2015
# File 'lib/MrMurano/optparse.rb', line 2013

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

#set_option(opt, eq) ⇒ Object



2017
2018
2019
2020
2021
2022
2023
2024
# File 'lib/MrMurano/optparse.rb', line 2017

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