Add a confirmation step to your rake tasks
Have you ever wanted to protect yourself from accidentally running a critical rake task? If so, start by creating a confirmation task:
task :confirm do
confirm_token = rand(36**6).to_s(36)
STDOUT.puts "Confirm [ACTION]? Enter '#{confirm_token}' to confirm:"
input = STDIN.gets.chomp
raise "Aborting [ACTION]. You entered #{input}" unless input == confirm_token
end
Of course replace [ACTION]
by something relevant (or something generic). This implementation generates a random 6-character string that you will need to enter before continuing.
You can then use it by calling it before your own tasks:
task :deploy_to_production => :confirm do
...
end
Your critical rake tasks are now safe from you!
Written by Michel Billard
Related protips
2 Responses
Awesome! from @railsonmaui.
over 1 year ago
·
Thank you!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#