Skip to content

Instantly share code, notes, and snippets.

@padde
Created October 22, 2015 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save padde/4862b1a351aeabe9c8e8 to your computer and use it in GitHub Desktop.
Save padde/4862b1a351aeabe9c8e8 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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