Permalink
Browse files

run rush with arguments to execute them instead of interactive shell

  • Loading branch information...
1 parent 8f658ea commit 433cfd3e5a71e40c02b084f2aebd15a2fcb02305 @adamwiggins committed Mar 27, 2008
Showing with 23 additions and 14 deletions.
  1. +7 −1 bin/rush
  2. +16 −13 lib/rush/shell.rb
View
@@ -3,5 +3,11 @@
require File.dirname(__FILE__) + '/../lib/rush'
require File.dirname(__FILE__) + '/../lib/rush/shell'
-Rush::Shell.new.run
+shell = Rush::Shell.new
+
+if ARGV.size > 0
+ shell.execute ARGV.join(' ')
+else
+ shell.run
+end
View
@@ -31,6 +31,21 @@ def initialize
Array.class_eval commands
end
+ # Run a single command.
+ def execute(cmd)
+ res = eval(cmd, @pure_binding)
+ $last_res = res
+ eval("_ = $last_res", @pure_binding)
+ print_result res
+ rescue Rush::Exception => e
+ puts "Exception #{e.class} -> #{e.message}"
+ rescue ::Exception => e
+ puts "Exception #{e.class} -> #{e.message}"
+ e.backtrace.each do |t|
+ puts " #{::File.expand_path(t)}"
+ end
+ end
+
# Run the interactive shell using readline.
def run
loop do
@@ -40,19 +55,7 @@ def run
next if cmd == ""
Readline::HISTORY.push(cmd)
- begin
- res = eval(cmd, @pure_binding)
- $last_res = res
- eval("_ = $last_res", @pure_binding)
- print_result res
- rescue Rush::Exception => e
- puts "Exception #{e.class} -> #{e.message}"
- rescue ::Exception => e
- puts "Exception #{e.class} -> #{e.message}"
- e.backtrace.each do |t|
- puts " #{::File.expand_path(t)}"
- end
- end
+ execute(cmd)
end
end

0 comments on commit 433cfd3

Please sign in to comment.