Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for -s on the cli. Fixes #879

  • Loading branch information...
commit 38a5f972c2401db77796443d9d83bd10213c0d0f 1 parent 851353e
@evanphx evanphx authored
Showing with 37 additions and 0 deletions.
  1. +37 −0 kernel/loader.rb
View
37 kernel/loader.rb
@@ -17,6 +17,8 @@ def initialize
@input_loop = false
@input_loop_print = false
@input_loop_split = false
+ @simple_options = false
+ @early_option_stop = false
@gem_bin = File.join Rubinius::GEMS_PATH, "bin"
end
@@ -176,6 +178,30 @@ def detect_alias
end
end
+ def handle_simple_options(argv)
+ argv.delete_if do |x|
+ if x[0] == ?-
+ if equal = x.index("=")
+ name = x.substring(1, equal-1)
+
+ equal += 1
+ val = x.substring(equal, x.size - equal)
+ else
+ name = x.substring(1, x.size - 1)
+ val = true
+ end
+
+ name.gsub! "-", "_"
+
+ Rubinius::Globals[:"$#{name}"] = val
+
+ true
+ else
+ false
+ end
+ end
+ end
+
# Process all command line arguments.
def options(argv=ARGV)
@stage = "processing command line arguments"
@@ -203,6 +229,7 @@ def options(argv=ARGV)
end
options.on "--", "Stop processing command line arguments" do
+ @early_option_stop = true
options.stop_parsing
end
@@ -286,6 +313,10 @@ def options(argv=ARGV)
@requires << file
end
+ options.on("-s", "Process options after the script into globals") do
+ @simple_options = true
+ end
+
options.on("-S", "SCRIPT",
"Run SCRIPT using PATH environment variable to find it") do |script|
options.stop_parsing
@@ -418,6 +449,10 @@ def options(argv=ARGV)
handle_rubyopt(options)
+ if @early_option_stop and @simple_options
+ handle_simple_options(argv)
+ end
+
if str = Rubinius::Config['tool.require']
begin
require str
@@ -556,6 +591,8 @@ def evals
def script
return unless @script and @evals.empty?
+ handle_simple_options(ARGV) if @simple_options
+
@stage = "running #{@script}"
Dir.chdir @directory if @directory
Please sign in to comment.
Something went wrong with that request. Please try again.