lib/rib/runner.rb in rib-1.1.6 vs lib/rib/runner.rb in rib-1.2.0
- old
+ new
@@ -64,24 +64,25 @@
(File.read(Gem.bin_path($1, $2))[/\n__END__\n(.+)$/m, 1] || '').strip
end
def run argv=ARGV
(@running_commands ||= []) << Rib.config[:name]
- unused = parse(argv)
+ unused, e = parse(argv)
# if it's running a Rib command, the loop would be inside Rib itself
# so here we only parse args for the command
return if @running_commands.pop != 'rib'
# by comming to this line, it means now we're running Rib main loop,
# not any other Rib command
Rib.warn("Unused arguments: #{unused.inspect}") unless unused.empty?
require 'rib/core' if Rib.config.delete(:mimic_irb)
+ Rib.shell.eval_binding.eval(e, __FILE__, __LINE__)
loop
end
def loop retry_times=5
Rib.shell.loop
- rescue Exception => e
+ rescue => e
if retry_times <= 0
Rib.warn("Error: #{e}. Too many retries, give up.")
elsif Rib.shells.last.running?
Rib.warn("Error: #{e}. Relaunching a new shell... ##{retry_times}")
Rib.warn("Backtrace: #{e.backtrace}") if $VERBOSE
@@ -94,23 +95,23 @@
Rib.warn("Backtrace: #{e.backtrace}") if $VERBOSE
end
end
def parse argv
- unused = []
+ unused, e = [], ''
until argv.empty?
case arg = argv.shift
when /^-e=?(.+)?/, /^--eval=?(.+)?/
- eval($1 || argv.shift, TOPLEVEL_BINDING, __FILE__, __LINE__)
+ e = $1 || argv.shift || ''
when /^-d/, '--debug'
$DEBUG = true
- argv.unshift("-#{arg[2..-1]}") if arg.size > 2
+ parse_next(argv, arg)
when /^-w/, '--warn'
$-w, $VERBOSE = true, true
- argv.unshift("-#{arg[2..-1]}") if arg.size > 2
+ parse_next(argv, arg)
when /^-I=?(.+)?/, /^--include=?(.+)?/
paths = ($1 || argv.shift).split(':')
$LOAD_PATH.unshift(*paths)
@@ -120,11 +121,11 @@
when /^-c=?(.+)?/, /^--config=?(.+)?/
Rib.config[:config] = $1 || argv.shift
when /^-n/, '--no-config'
Rib.config.delete(:config)
- argv.unshift("-#{arg[2..-1]}") if arg.size > 2
+ parse_next(argv, arg)
when /^-h/, '--help'
puts(help)
exit
@@ -138,15 +139,20 @@
else
unused << arg
end
end
- unused
+ [unused, e]
end
+ def parse_next argv, arg
+ argv.unshift("-#{arg[2..-1]}") if arg.size > 2
+ end
+
def help
- maxn = options.transpose.first.map(&:size).max
- maxd = options.transpose.last .map(&:size).max
+ optt = options.transpose
+ maxn = optt.first.map(&:size).max
+ maxd = optt.last .map(&:size).max
"Usage: #{Rib.config[:name]}" \
" [ruby OPTIONS] [rib OPTIONS] [rib COMMANDS]\n" +
options.map{ |(name, desc)|
if name.end_with?(':')
name