Exception: OptionParser::ParseError

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

Overview

Base class of exceptions from OptionParser.

Constant Summary collapse

Reason =

Reason which caused the error.

'parse error'
DIR =
File.join(__dir__, '')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, additional: nil) ⇒ ParseError

:nodoc:



2260
2261
2262
2263
2264
2265
# File 'lib/llm/shell/internal/optparse/lib/optparse.rb', line 2260

def initialize(*args, additional: nil)
  @additional = additional
  @arg0, = args
  @args = args
  @reason = nil
end

Instance Attribute Details

#additionalObject

Returns the value of attribute additional.



2269
2270
2271
# File 'lib/llm/shell/internal/optparse/lib/optparse.rb', line 2269

def additional
  @additional
end

#argsObject (readonly)

Returns the value of attribute args.



2267
2268
2269
# File 'lib/llm/shell/internal/optparse/lib/optparse.rb', line 2267

def args
  @args
end

#reasonObject

Returns error reason. Override this for I18N.



2303
2304
2305
# File 'lib/llm/shell/internal/optparse/lib/optparse.rb', line 2303

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

Class Method Details

.filter_backtrace(array) ⇒ Object



2280
2281
2282
2283
2284
2285
# File 'lib/llm/shell/internal/optparse/lib/optparse.rb', line 2280

def self.filter_backtrace(array)
  unless $DEBUG
    array.delete_if {|bt| bt.start_with?(DIR)}
  end
  array
end

Instance Method Details

#inspectObject



2307
2308
2309
# File 'lib/llm/shell/internal/optparse/lib/optparse.rb', line 2307

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

#messageObject Also known as: to_s

Default stringizing method to emit standard error message.



2314
2315
2316
# File 'lib/llm/shell/internal/optparse/lib/optparse.rb', line 2314

def message
  "#{reason}: #{args.join(' ')}#{additional[@arg0] if additional}"
end

#recover(argv) ⇒ Object

Pushes back erred argument(s) to argv.



2274
2275
2276
2277
# File 'lib/llm/shell/internal/optparse/lib/optparse.rb', line 2274

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

#set_backtrace(array) ⇒ Object



2287
2288
2289
# File 'lib/llm/shell/internal/optparse/lib/optparse.rb', line 2287

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

#set_option(opt, eq) ⇒ Object



2291
2292
2293
2294
2295
2296
2297
2298
# File 'lib/llm/shell/internal/optparse/lib/optparse.rb', line 2291

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