Skip to content
Browse files

Move handling a file, as input, back to bin/dietrb. And add option fo…

…r selecting a driver.
  • Loading branch information...
1 parent 01711aa commit 919d02cfd943ad6b0d117b1387a1ea7dd04bee84 @alloy committed Jul 24, 2010
Showing with 20 additions and 32 deletions.
  1. +20 −15 bin/dietrb
  2. +0 −17 lib/irb/driver/file.rb
View
35 bin/dietrb
@@ -5,18 +5,20 @@ require 'irb'
unless ARGV.empty?
require 'optparse'
+ driver = nil
ignore_irbrc = false
OptionParser.new do |opt|
bin = File.basename($0)
opt.banner = "Usage: #{bin} [options] [programfile] [arguments]"
- opt.on("-f", "Ignore ~/.irbrc") { |ignore| ignore_irbrc = ignore }
- opt.on("-r load-lib", "Loads the given library (same as `ruby -r')") { |lib| require lib }
- opt.on("-d", "Set $DEBUG to true (same as `ruby -d')") { $DEBUG = true }
- opt.on("-I path", "Add path to $LOAD_PATH") { |path| $LOAD_PATH.unshift(path) }
- opt.on("--noinspect", "Don't use inspect for output") { IRB.formatter.inspect = false }
- opt.on("--simple-prompt", "Simple prompt mode") { IRB.formatter.prompt = :simple }
- opt.on("--noprompt", "No prompt mode") { IRB.formatter.prompt = nil }
+ opt.on("-f", "Ignore ~/.irbrc") { |i| ignore_irbrc = i }
+ opt.on("-r load-lib", "Loads the given library (same as `ruby -r')") { |l| require l }
+ opt.on("-d", "Set $DEBUG to true (same as `ruby -d')") { $DEBUG = true }
+ opt.on("-I path", "Add path to $LOAD_PATH") { |p| $LOAD_PATH.unshift(p) }
+ opt.on("--driver name", "As driver, use one of: tty, readline, or socket") { |d| driver = d }
+ opt.on("--noinspect", "Don't use inspect for output") { IRB.formatter.inspect = false }
+ opt.on("--simple-prompt", "Simple prompt mode") { IRB.formatter.prompt = :simple }
+ opt.on("--noprompt", "No prompt mode") { IRB.formatter.prompt = nil }
opt.on("-v", "--version", "Print the version of #{bin}") do
$stdout.puts IRB::VERSION::DESCRIPTION
exit
@@ -32,13 +34,16 @@ end
IRB.formatter.filter_from_backtrace << /^#{__FILE__}/
if ARGV.empty?
- require 'irb/driver/readline'
- # require 'irb/driver/tty'
- # require 'irb/driver/socket'
+ driver ||= begin
+ require 'readline'
+ 'readline'
+ rescue LoadError
+ 'tty'
+ end
+ require "irb/driver/#{driver}"
+ irb(self, TOPLEVEL_BINDING.dup)
else
path = ARGV.shift
- require 'irb/driver/file'
- IRB::Driver.current = IRB::Driver::File.new(path)
-end
-
-irb(self, TOPLEVEL_BINDING.dup)
+ context = IRB::Context.new(self, TOPLEVEL_BINDING.dup)
+ File.open(path, 'r') { |f| f.each_line { |line| context.input_line(line) } }
+end
View
17 lib/irb/driver/file.rb
@@ -1,17 +0,0 @@
-require 'irb/driver/tty'
-
-module IRB
- module Driver
- class File
- def initialize(path)
- @path = path
- end
-
- def run(context)
- ::File.open(@path, 'r') do |file|
- file.each_line { |line| context.input_line(line) }
- end
- end
- end
- end
-end

0 comments on commit 919d02c

Please sign in to comment.
Something went wrong with that request. Please try again.