Skip to content

Instantly share code, notes, and snippets.

@padde

padde/Rakefile

Created Oct 22, 2015
Embed
What would you like to do?
Pass options hash to Rake
module RakeOptionParser
def self.parse(args)
args.extras.each_with_object({}) do |arg, result|
key, value = arg.split(/:\s*/, 2)
result[key.to_sym] = value
end
end
end
namespace :foo do
task :bar, [] => :environment do |t, args|
options = RakeOptionParser.parse(args)
p options
end
end
@padde

This comment has been minimized.

Copy link
Owner Author

@padde padde commented Oct 22, 2015

Usage

$ rake 'foo:bar[baz:1,quux:test]'
{:baz=>"1", :quux=>"test"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment