我想創建一個沒有參數的參數的rake任務。OptionParser :: MissingArgument
task :mytask => :environment do
options = Hash.new
OptionParser.new do |opts|
opts.on('-l', '--local', 'Run locally') do
options[:local] = true
end
end.parse!
# some code
end
但它拋出:
$ rake mytask -l
rake aborted!
OptionParser::MissingArgument: missing argument: -l
同時:
$ rake mytask -l random_arg
ready
爲什麼?
- 耙10.4.2
- JRuby的1.7.13
我不知道OptionParser是這裏最好的計劃。 'rake'已經有了自己的選項解析和一個方法,最後在'VAR = value'處傳入數據,就像'LOCAL = 1'一樣。看到[這個答案](http://stackoverflow.com/questions/825748/how-to-pass-command-line-arguments-to-a-rake-task)爲例。 – tadman
@tadman我希望有我的選擇,因爲標誌 – Viktor