Skip to content

Instantly share code, notes, and snippets.

@altherlex
Created April 20, 2016 19:10
Show Gist options
  • Save altherlex/bb67f17cb8eefb281866fc21dfeb921a to your computer and use it in GitHub Desktop.
Save altherlex/bb67f17cb8eefb281866fc21dfeb921a to your computer and use it in GitHub Desktop.
How use optparse gem into rake tasks
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