Permalink
Browse files

added '--' argument syntax

  • Loading branch information...
1 parent 84da101 commit 4a19133c1a31047ca02334424fd6cfb254122ac9 @thinkerbot committed Feb 25, 2011
Showing with 41 additions and 2 deletions.
  1. +31 −2 lib/rake/application.rb
  2. +10 −0 test/lib/application_test.rb
View
@@ -122,6 +122,10 @@ def parse_task_string(string)
end
[name, args]
end
+
+ def format_task_string(args)
+ "#{args.shift}[#{args.join(',')}]"
+ end
# Provide standard exception handling for the given block.
def standard_exception_handling
@@ -421,6 +425,12 @@ def handle_options
end
standard_rake_options.each { |args| opts.on(*args) }
+
+ opts.on_tail("--", "Turn on arg syntax ('-- a b c' => 'a[b,c]')") do
+ # restores option break to ARGV if found, allowing arg syntax
+ throw :terminate, "--"
+ end
+
opts.environment('RAKEOPT')
end.parse!
@@ -532,13 +542,32 @@ def standard_system_dir #:nodoc:
# Environmental assignments are processed at this time as well.
def collect_tasks
@top_level_tasks = []
+
+ current = nil
ARGV.each do |arg|
- if arg =~ /^(\w+)=(.*)$/
+ case arg
+ when '--'
+ if current && !current.empty?
+ @top_level_tasks << format_task_string(current)
+ end
+ current = []
+ when /^(\w+)=(.*)$/
ENV[$1] = $2
+ when /^-/
+ next
else
- @top_level_tasks << arg unless arg =~ /^-/
+ if current
+ current << arg
+ else
+ @top_level_tasks << arg
+ end
end
end
+
+ if current && !current.empty?
+ @top_level_tasks << format_task_string(current)
+ end
+
@top_level_tasks.push("default") if @top_level_tasks.size == 0
end
@@ -658,6 +658,16 @@ def test_task_collection
assert_equal ["a", "b"], @tasks.sort
end
+ def test_task_collection_of_arg_syntax
+ command_line("a", "--", "b", "c", "d", "--", "x", "y", "z")
+ assert_equal ["a", "b[c,d]", "x[y,z]"], @tasks.sort
+ end
+
+ def test_task_collection_ignores_empty_arg_syntax
+ command_line("a", "--", "--")
+ assert_equal ["a"], @tasks.sort
+ end
+
def test_default_task_collection
command_line()
assert_equal ["default"], @tasks

0 comments on commit 4a19133

Please sign in to comment.