你能告诉我一个快速的工作片段来解决这个命令行选项的情况吗?(Can you show me a quick working snippet to solve this command line option case?)
我希望能够从命令行运行我的脚本时支持这样的事情:
script.rb -n 2 -t first.txt -t second.txt我希望能够拿到1个或更多的t开关,但我不知道如何实现这一点。 我想不必这样做:
script.rb -n 2 -tfirst.txt,second.txt有什么想法?
I'd like to be able to support something like this when running my script from the command line:
script.rb -n 2 -t first.txt -t second.txtI'd like to be able to take 1 or more t switches, but I have no clue how to achieve this. I would like to not have to do this:
script.rb -n 2 -tfirst.txt,second.txtGot any ideas?
最满意答案
您可能想要使用OptionParser http://ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
会有这样的工作吗?
require 'optparse' files = [] OptionParser.new do |opts| opts.on("-t", "--text-file TEXTFILE","Text file to run against" ) do |text_file_name| files << text_file_name end end.parse! puts files.inspectYou might want to use OptionParser http://ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
Would something like this work ?
require 'optparse' files = [] OptionParser.new do |opts| opts.on("-t", "--text-file TEXTFILE","Text file to run against" ) do |text_file_name| files << text_file_name end end.parse! puts files.inspect更多推荐
发布评论