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.



1938
1939
1940
1941
# File 'lib/optparse.rb', line 1938

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args



1943
1944
1945
# File 'lib/optparse.rb', line 1943

def args
  @args
end

#reasonObject

Returns error reason. Override this for I18N.



1977
1978
1979
# File 'lib/optparse.rb', line 1977

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

Class Method Details

.filter_backtrace(array) ⇒ Object



1954
1955
1956
1957
1958
1959
# File 'lib/optparse.rb', line 1954

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

Instance Method Details

#inspectObject



1981
1982
1983
# File 'lib/optparse.rb', line 1981

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

#messageObject Also known as: to_s

Default stringizing method to emit standard error message.



1988
1989
1990
# File 'lib/optparse.rb', line 1988

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

#recover(argv) ⇒ Object

Pushes back erred argument(s) to argv.



1949
1950
1951
1952
# File 'lib/optparse.rb', line 1949

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

#set_backtrace(array) ⇒ Object



1961
1962
1963
# File 'lib/optparse.rb', line 1961

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

#set_option(opt, eq) ⇒ Object



1965
1966
1967
1968
1969
1970
1971
1972
# File 'lib/optparse.rb', line 1965

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