Browse files

Make bin/sequel accept file arguments and work correctly when $stdin …

…is not a tty

Previously, unless the -m, -C, -d, or -D options was given,
bin/sequel always gave an IRB prompt.  This changes that behavior
so that if any arguments are present, they are interpreted as
filenames and are loaded.  Also, if $stdin is not a tty, it is
read from and evaled.  These changes make bin/sequel operate more
like a standard *nix program.

For recent Linux users, this also means you can have a shebang
line such as:

  #!/usr/bin/sequel postgres://user:pass@host/db

to create a self contained script, where you can have ruby
code in the script, with the DB constant already set.  This
is because recent Linux versions (since 2.6.28) support
recursion in the #! handling.
  • Loading branch information...
1 parent 05c6633 commit 8409e076c3b353a05d923f90c404f26602d731f7 @jeremyevans committed Feb 14, 2011
Showing with 11 additions and 3 deletions.
  1. +2 −0 CHANGELOG
  2. +9 −3 bin/sequel
@@ -1,5 +1,7 @@
=== HEAD
+* Make bin/sequel accept file arguments and work correctly when $stdin is not a tty (jeremyevans)
* Add support for -I and -r options to bin/sequel (jeremyevans)
* Sequel::Model.plugin can now be overridden just like the other Model methods (jeremyevans)
@@ -198,6 +198,12 @@ rescue => e
error_proc["Error: #{e.class}: #{e.message}#{e.backtrace.first}"]
-require 'irb'
-puts "Your database is stored in DB..."
+if !ARGV.empty?
+ ARGV.each{|v| load(v)}
+elsif !$stdin.isatty
+ eval($
+ require 'irb'
+ puts "Your database is stored in DB..."
+ IRB.start

0 comments on commit 8409e07

Please sign in to comment.