1
這是我的解析器:紅寶石OptionParser不設置參數
options = { frames: 12, showcurrent: false}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: example.rb [options]"
opts.on("-f", "--frames", "Only tickets of the last x time frames (default: 12)", Integer) { |v| options[:frames] = v }
opts.on("-c", "--show_current", "Show current (false (default) ot true)") { |v| options[:showcurrent] = v }
opts.on("-t", "--time", "Type of the report (day, week (default), month, quarter, year)", String) { |v| options[:time] = v }
opts.on("-w", "--year_week YEAR-WEEK", "wrYYWW (wr1707)", String) { |v| options[:yw] = v }
end
optparse.parse!
puts options
後我運行ruby main.rb -t 'w' -w 'wr1707'
選項的代碼如下:
{:frames=>12, :showcurrent=>false, :time=>nil, :yw=>"wr1707"}
出於某種原因,選項[:時間]沒有設置,我不明白爲什麼。是否可能存在轉換問題,我不允許使用-t作爲參數?