Reffering that answer I was trying to use OptionParser
to parse rake
arguments. I simplified example from there and I had to add two ARGV.shi
I know this does not strictly answer your question, but did you consider using task arguments?
That would free you having to fiddle with OptionParser
and ARGV
:
namespace :user do |args|
desc 'Creates user account with given credentials: rake user:create'
task :create, [:username] => :environment do |t, args|
# when called with rake user:create[foo],
# args is now {username: 'foo'} and you can access it with args[:username]
end
end
For more info, see this answer here on SO.