I am using Ruby OptionParser but can not figure out how to get non-option arguments as two lists.
myscript --option-one --option-two file1 file2 -- file10 file11
Is there a way to get from OptionParser two lists of files separately?
[file1, file2]
[file10, file11]
I do not care which of them remains in ARGV, just want to have two lists separately to submit them to different processing.
My current solution is
adding a handler of
--
as followsopts.on('--', 'marks the beginning of a different list of files') do ARGV.unshift(:separator) end
this produces ARGV with the following content
[ file1, file2, :separator, file10, file11 ]
and then, outside of OptionParser and after
parse!
was called, I modifyARGV
list1 = ARGV.shift(ARGV.index(:separator)) ARGV.shift
Is there a more elegant way of accomplishing it?