From bdb31e3bba1907e5254eae870d90a359f86b6f3e Mon Sep 17 00:00:00 2001 From: pivotal Date: Fri, 31 Oct 2008 17:09:24 -0700 Subject: [PATCH] am - Options parsing now appropriately removed rake options from the argument array. --- lib/rake.rb | 32 ++++++++++++++++---------------- test/test_application.rb | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/lib/rake.rb b/lib/rake.rb index 9fe4e543e..591bdbc1e 100755 --- a/lib/rake.rb +++ b/lib/rake.rb @@ -1984,7 +1984,8 @@ def run def init(app_name='rake') standard_exception_handling do @name = app_name - collect_tasks handle_options + handle_options + collect_tasks end end @@ -2287,18 +2288,18 @@ def standard_rake_options def handle_options options.rakelib = ['rakelib'] - opts = OptionParser.new - opts.banner = "rake [-f rakefile] {options} targets..." - opts.separator "" - opts.separator "Options are ..." - - opts.on_tail("-h", "--help", "-H", "Display this help message.") do - puts opts - exit - end - - standard_rake_options.each { |args| opts.on(*args) } - parsed_argv = opts.parse(ARGV) + OptionParser.new do |opts| + opts.banner = "rake [-f rakefile] {options} targets..." + opts.separator "" + opts.separator "Options are ..." + + opts.on_tail("-h", "--help", "-H", "Display this help message.") do + puts opts + exit + end + + standard_rake_options.each { |args| opts.on(*args) } + end.parse! # If class namespaces are requested, set the global options # according to the values in the options structure. @@ -2309,7 +2310,6 @@ def handle_options $dryrun = options.dryrun $silent = options.silent end - parsed_argv end # Similar to the regular Ruby +require+ command, but will check @@ -2396,9 +2396,9 @@ def standard_system_dir #:nodoc: # Collect the list of tasks on the command line. If no tasks are # given, return a list containing only the default task. # Environmental assignments are processed at this time as well. - def collect_tasks(argv) + def collect_tasks @top_level_tasks = [] - argv.each do |arg| + ARGV.each do |arg| if arg =~ /^(\w+)=(.*)$/ ENV[$1] = $2 else diff --git a/test/test_application.rb b/test/test_application.rb index 8ce1ac69f..40503ec56 100644 --- a/test/test_application.rb +++ b/test/test_application.rb @@ -232,6 +232,19 @@ def test_building_imported_files_on_demand end end + def test_handle_options__should_strip_options_from_ARGV + assert !@app.options.trace + + valid_option = '--trace' + ARGV.clear + ARGV << valid_option + + @app.handle_options + + assert !ARGV.include?(valid_option) + assert @app.options.trace + end + def test_good_run ran = false ARGV.clear @@ -596,7 +609,8 @@ def @app.exit(*args) throw :system_exit, :exit end @app.instance_eval do - collect_tasks handle_options + handle_options + collect_tasks end @tasks = @app.top_level_tasks @app.options