在ruby中,Slop解析每个参数具有多个输入的命令行参数选项

在ruby中,Slop解析每个参数具有多个输入的命令行参数选项,ruby,parsing,command-line-interface,Ruby,Parsing,Command Line Interface,我正在ruby中使用Slop解析输入参数: slop_opts = Slop.parse(ARGV.map(&:strip)) do |o| o.string '--test1', 'explain test1' o.string '--test2', 'explain test2'

我正在ruby中使用Slop解析输入参数:

slop_opts = Slop.parse(ARGV.map(&:strip)) do |o|                                
  o.string '--test1', 'explain test1'                             
  o.string '--test2', 'explain test2'                                      
  o.on '--help' do                                                              
    puts o                                                                      
    exit                                                                        
  end                                                                           
end                                                                             
                                                                                
slop_opts.to_hash      
我需要
test2
可以包括几个选项: e、 g

我的一个限制是,我需要first_arg和second_arg是两个不同的输入,所以我不能仅仅通过拆分
(或类似)像
first_arg,second_arg这样的输入字符串来获取它们

谢谢你的帮助

使
--test2
成为一个。将分隔符设置为
nil
以禁用拆分输入

slop_opts = Slop.parse(ARGV.map(&:strip)) do |o|                                
  o.string '--test1', 'explain test1'                             
  o.array '--test2', 'explain test2', delimiter: nil                                  
  o.on '--help' do                                                              
    puts o                                                                      
    exit                                                                        
  end                                                                           
end  
然后每个输入都有自己的
——test2

ruby this_script.rb --test1 one_arg --test2 first_arg --test2 second_arg
ruby this_script.rb --test1 one_arg --test2 first_arg --test2 second_arg