Created
April 20, 2016 19:10
-
-
Save altherlex/bb67f17cb8eefb281866fc21dfeb921a to your computer and use it in GitHub Desktop.
How use optparse gem into rake tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'optparse' | |
namespace :programs do |args| | |
desc "Download whatever" | |
task :download => [:environment] do | |
# USAGE: rake programs:download -- rm | |
#-- Setting options $ rake programs:download -- --rm | |
options = {} | |
option_parser = OptionParser.new | |
option_parser.banner = "Usage: rake programs:download -- rm" | |
option_parser.on("-r", "--rm","Remove s3 files downloaded") do |value| | |
options[:remove] = value | |
end | |
args = option_parser.order!(ARGV) {} | |
option_parser.parse!(args) | |
#-- end | |
# your code here | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment