Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add bin/sequel -c support, for running code string instead of using a…

…n IRB prompt

You could previously have done this by piping the code to the
standard input, but this is definitely easier.  Would have
preferred to use the -e option so that executing code is similar
to ruby, but since that was taken, I choose to use -c since that
is similar to sh.
  • Loading branch information...
commit fbceb248104f82d1b45280c9569d1cd1bab754ef 1 parent 6ddc157
Jeremy Evans authored
Showing with 14 additions and 2 deletions.
  1. +2 −0  CHANGELOG
  2. +12 −2 bin/sequel
2  CHANGELOG
View
@@ -1,5 +1,7 @@
=== HEAD
+* Add bin/sequel -c support, for running code string instead of using an IRB prompt (jeremyevans)
+
* Allow subclasses plugin to take a block, which is called with all subclasses created (jeremyevans)
* Add :where option to validates_unique, for custom uniqueness filters (jeremyevans)
14 bin/sequel
View
@@ -4,6 +4,7 @@ require 'rubygems'
require 'optparse'
require 'sequel'
+code = nil
copy_databases = nil
dump_migration = nil
dump_schema = nil
@@ -18,7 +19,7 @@ loggers = []
opts = OptionParser.new do |opts|
opts.banner = "Sequel: The Database Toolkit for Ruby"
- opts.define_head "Usage: sequel <uri|path> [options]"
+ opts.define_head "Usage: sequel [options] <uri|path> [file]"
opts.separator ""
opts.separator "Examples:"
opts.separator " sequel sqlite://blog.db"
@@ -34,6 +35,11 @@ opts = OptionParser.new do |opts|
exit
end
+ opts.on("-c", "--code CODE", "run the given code and exit") do |v|
+ code = v
+ exclusive_options << :c
+ end
+
opts.on("-C", "--copy-databases", "copy one database to another") do
copy_databases = true
end
@@ -83,7 +89,7 @@ opts = OptionParser.new do |opts|
test = false
end
- opts.on("-r", "--require lib", "require the library, before executing your script") do |v|
+ opts.on("-r", "--require LIB", "require the library, before executing your script") do |v|
load_dirs << [v]
end
@@ -207,6 +213,10 @@ begin
puts "Database copy finished in #{Time.now - start_time} seconds"
exit
end
+ if code
+ eval(code)
+ exit
+ end
rescue => e
raise e if backtrace
error_proc["Error: #{e.class}: #{e.message}#{e.backtrace.first}"]
Please sign in to comment.
Something went wrong with that request. Please try again.