How to parse rake arguments with OptionParser

前端 未结 4 509
情书的邮戳
情书的邮戳 2021-01-18 00:05

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

4条回答
  •  生来不讨喜
    2021-01-18 00:33

    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.

提交回复
热议问题