def IRB.parse_opts(argv: ::ARGV)
load_path = []
while opt = argv.shift
case opt
when "-f"
@CONF[:RC] = false
when "-d"
$DEBUG = true
$VERBOSE = true
when "-w"
$VERBOSE = true
when /^-W(.+)?/
opt = $1 || argv.shift
case opt
when "0"
$VERBOSE = nil
when "1"
$VERBOSE = false
else
$VERBOSE = true
end
when /^-r(.+)?/
opt = $1 || argv.shift
@CONF[:LOAD_MODULES].push opt if opt
when /^-I(.+)?/
opt = $1 || argv.shift
load_path.concat(opt.split(File::PATH_SEPARATOR)) if opt
when '-U'
set_encoding("UTF-8", "UTF-8")
when /^-E(.+)?/, /^--encoding(?:=(.+))?/
opt = $1 || argv.shift
set_encoding(*opt.split(':', 2))
when "--inspect"
if /^-/ !~ argv.first
@CONF[:INSPECT_MODE] = argv.shift
else
@CONF[:INSPECT_MODE] = true
end
when "--noinspect"
@CONF[:INSPECT_MODE] = false
when "--readline"
@CONF[:USE_READLINE] = true
when "--noreadline"
@CONF[:USE_READLINE] = false
when "--echo"
@CONF[:ECHO] = true
when "--noecho"
@CONF[:ECHO] = false
when "--verbose"
@CONF[:VERBOSE] = true
when "--noverbose"
@CONF[:VERBOSE] = false
when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
opt = $1 || argv.shift
prompt_mode = opt.upcase.tr("-", "_").intern
@CONF[:PROMPT_MODE] = prompt_mode
when "--noprompt"
@CONF[:PROMPT_MODE] = :NULL
when "--inf-ruby-mode"
@CONF[:PROMPT_MODE] = :INF_RUBY
when "--sample-book-mode", "--simple-prompt"
@CONF[:PROMPT_MODE] = :SIMPLE
when "--tracer"
@CONF[:USE_TRACER] = true
when /^--back-trace-limit(?:=(.+))?/
@CONF[:BACK_TRACE_LIMIT] = ($1 || argv.shift).to_i
when /^--context-mode(?:=(.+))?/
@CONF[:CONTEXT_MODE] = ($1 || argv.shift).to_i
when "--single-irb"
@CONF[:SINGLE_IRB] = true
when /^--irb_debug(?:=(.+))?/
@CONF[:DEBUG_LEVEL] = ($1 || argv.shift).to_i
when "-v", "--version"
print IRB.version, "\n"
exit 0
when "-h", "--help"
require_relative "help"
IRB.print_usage
exit 0
when "--"
if opt = argv.shift
@CONF[:SCRIPT] = opt
$0 = opt
end
break
when /^-/
IRB.fail UnrecognizedSwitch, opt
else
@CONF[:SCRIPT] = opt
$0 = opt
break
end
end
load_path.collect! do |path|
/\A\.\// =~ path ? path : File.expand_path(path)
end
$LOAD_PATH.unshift(*load_path)
end