【发布时间】:2009-04-06 13:02:35
【问题描述】:
我正在尝试使用optparse 来解析命令行参数。我希望我的程序接受这样的参数:
$ ./myscript.rb [options] filename
我可以轻松管理[options] 部分:
require 'optparse'
options = { :verbose => false, :type => :html }
opts = OptionParser.new do |opts|
opts.on('-v', '--verbose') do
options[:verbose] = true
end
opts.on('-t', '--type', [:html, :css]) do |type|
options[:type] = type
end
end
opts.parse!(ARGV)
但是我如何获得filename?
我可以从ARGV手动提取它,但必须有更好的解决方案,只是不知道如何
【问题讨论】: