Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 1.55 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. @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:
  2.  
  3. ```bash
  4. # [Rakefile]
  5. # task :standard_echo, :a, :b do |t, args|
  6. #   message = ENV['MESSAGE'] || 'got'
  7. #   puts "#{message}: #{args.a} #{args.b}"
  8. # end
  9. #
  10. # cmd  :cmd_echo, :a, :b, %{
  11. #   -m,--message [got]  : A message
  12. # } do |config, args|
  13. #   puts "#{config.message}: #{args.a} #{args.b}"
  14. # end
  15.  
  16. rake standard_echo[a,b]
  17. # got: a b
  18. rake standard_echo['a,b',c]
  19. # got: a b
  20.  
  21. rake -- cmd_echo a b
  22. # got: a b
  23. rake -- cmd_echo 'a,b' c
  24. # got: a b
  25. ```
  26.  
  27. 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.
  28.  
  29. ```bash
  30. # [Rakefile (continued)]
  31. # task :standard_one do
  32. #   puts(ENV['MESSAGE'] || 'got')
  33. # end
  34. # task :standard_two do
  35. #   puts(ENV['MESSAGE'] || 'got')
  36. # end
  37. #
  38. # cmd :cmd_one, %{
  39. #   -m,--message [got] : A message
  40. # } do |config, args|
  41. #   puts config.message
  42. # end
  43. # cmd :cmd_two, %{
  44. #   -m,--message [got] : A message
  45. # } do |config, args|
  46. #   puts config.message
  47. # end
  48.  
  49. rake standard_one MESSAGE=hello standard_two MESSAGE=goodbye
  50. # goodbye
  51. # goodbye
  52.  
  53. rake -- cmd_one -m hello -- cmd_two -m goodbye
  54. # hello
  55. # goodbye
  56. ```