title: How to parse rake arguments with OptionParser
body: <p>Reffering <a href="https://stackoverflow.com/questions/825748/how-do-i-pass-command-line-arguments-to-a-rake-task#answer-19466362">that answer</a> I was trying to use <code>OptionParser</code> to parse <code>rake</code> arguments. I simplified example from there and I had to add two <code>ARGV.shift</code> to make it work.</p>
  
  <pre><code>require 'optparse'
  
  namespace :user do |args|
  
    # Fix I hate to have here
    puts "ARGV: #{ARGV}"
    ARGV.shift
    ARGV.shift
    puts "ARGV: #{ARGV}"
  
    desc 'Creates user account with given credentials: rake user:create'
    # environment is required to have access to Rails models
    task :create =&gt; :environment do
      options = {}
      OptionParser.new(args) do |opts|      
        opts.banner = "Usage: rake user:create [options]"
        opts.on("-u", "--user {username}","Username") { |user| options[:user] = user }
      end.parse!
  
      puts "user: #{options[:user]}"
  
      exit 0
    end
  end
  </code></pre>
  
  <p>This is the output:</p>
  
  <pre><code>$ rake user:create -- -u foo
  ARGV: ["user:create", "--", "-u", "foo"]
  ARGV: ["-u", "foo"]
  user: foo
  </code></pre>
  
  <p>I assume <code>ARGV.shift</code> is not the way it should be done. I would like to know why it doesn't work without it and how to fix it in a proper way. </p>