Skip to content

Instantly share code, notes, and snippets.

@dfang
Last active August 29, 2015 14:17
Show Gist options
  • Save dfang/68f5b7667965f54dbe5c to your computer and use it in GitHub Desktop.
Save dfang/68f5b7667965f54dbe5c to your computer and use it in GitHub Desktop.
passing arguments to rake/cap task

there are two ways to passing args to rake task
please refer to https://itshouldbeuseful.wordpress.com/2011/11/07/passing-parameters-to-a-rake-task/
$ rake say_hello[eddie], or rake say_hello name='eddie'

desc 'say hello'
task :say_hello1 do
  name = ENV['name']
  puts "Hello, #{name}."
end
# $ rake say_hello1 name=eddie

task :say_hello2, :name, :a, :b do |t, args|
  binding.pry
  name = args.name
  puts "Hello, #{name}."
end
# rake say_hello[eddie,2,2]
#
# [1] pry(main)> args
# => {:name=>"eddie", :a=>"2", :b=>"2"}]

about passing args to rake task, cap task in zshell
in zsh: noglob option, in action. Rake tasks can take arguments in hard brackets. These brackets have special meaning in zsh. So, either turn off the special expansion stuff (noglob) or escape the brackets.

links:
https://robots.thoughtbot.com/how-to-use-arguments-in-a-rake-task
http://dev.scottw.com/zsh-rake-parameters
if you set it properly then you don't need to run like cap production "invoke:rake[db:drop]", just cap production invoke:rake[db:drop]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment