The documentation for Ruby's GetoptLong gave me the impression that it would remove the parsed options from ARGV. Here's the passage in question:
For example, if -a does not require an argument and -b optionally takes an argument, parsing ’-a one -b two three’ would result in (’-a’,’’) and (’-b’, ‘two’) being processed as option/arg pairs, and ‘one’,’three’ being left in ARGV.
However, this doesn't seem to be the case. Here is my program:
#!/usr/bin/env ruby
require "getoptlong"
opts = GetoptLong.new(
["--start", "-s", GetoptLong::REQUIRED_ARGUMENT],
["--base", "-b", GetoptLong::REQUIRED_ARGUMENT]
)
puts ARGV
And here is the output:
$ number-photos --start 2 --base foo *
--start
2
--base
foo
aac-to-mp3
backup-wp-uploads
exiv-webcam-imgs
get-updates
music-to-lily
number-photos
ogg-to-mp3
rename-music
restore-uploads
resymlink
sprints
sync-jt
sync-st
timestamp
unix-names
(I did check that I'm on ruby 1.9.2.)
I could remove the options manually, but this would be a bit of a headache since, depending on how you pass them in, each could take up either one or two slots in the array (--base=foo
vs. --base foo
). It would be much more convenient if GetoptLong could remove them for me. Is there any way to do this?