
Untitled
By: a guest on
Apr 28th, 2012 | syntax:
None | size: 1.55 KB | hits: 13 | expires: Never
@richmeyers for the most part I agree with your opinion but I should clarify that the '--' syntax does nothing to fix the escape issues. Commas cannot be specified using either syntax. Here are some examples - see this [gist](https://gist.github.com/1027463) to run these yourself:
```bash
# [Rakefile]
# task :standard_echo, :a, :b do |t, args|
# message = ENV['MESSAGE'] || 'got'
# puts "#{message}: #{args.a} #{args.b}"
# end
#
# cmd :cmd_echo, :a, :b, %{
# -m,--message [got] : A message
# } do |config, args|
# puts "#{config.message}: #{args.a} #{args.b}"
# end
rake standard_echo[a,b]
# got: a b
rake standard_echo['a,b',c]
# got: a b
rake -- cmd_echo a b
# got: a b
rake -- cmd_echo 'a,b' c
# got: a b
```
To answer your question, one of the benefits of per-task options is that you can specify different options for different tasks. This is not possible with the ENV syntax, or at least opens you up to collisions because ENV is global. Sometimes you do want global options; this proposal provides per-task options when you don't.
```bash
# [Rakefile (continued)]
# task :standard_one do
# puts(ENV['MESSAGE'] || 'got')
# end
# task :standard_two do
# puts(ENV['MESSAGE'] || 'got')
# end
#
# cmd :cmd_one, %{
# -m,--message [got] : A message
# } do |config, args|
# puts config.message
# end
# cmd :cmd_two, %{
# -m,--message [got] : A message
# } do |config, args|
# puts config.message
# end
rake standard_one MESSAGE=hello standard_two MESSAGE=goodbye
# goodbye
# goodbye
rake -- cmd_one -m hello -- cmd_two -m goodbye
# hello
# goodbye
```