Skip to content

Commit

Permalink
am - Options parsing now appropriately removed rake options from the …
Browse files Browse the repository at this point in the history
…argument array.
  • Loading branch information
pivotal committed Nov 1, 2008
1 parent 614e7a7 commit bdb31e3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
32 changes: 16 additions & 16 deletions lib/rake.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion test/test_application.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bdb31e3

Please sign in to comment.