From: Jim Freeze Date: 2002-07-31T13:37:05+09:00 Subject: Re: Question about GetoptLong On Wed, Jul 31, 2002 at 01:31:07PM +0900, Patrick Bennett wrote: > I'm trying to recreate a Perl script in Ruby and have run into a problem. > The perl script has several layered subroutines. The main entry point > has code like this: > > Getopt::Long::Configure(pass_through, no_auto_abbrev); > GetOptions('logfile' => \$logfile, 'log' => \$log, 'leave_tempfiles' > => \$leave_tempfiles, 'batch_length=i' => \$batch_length); > Getopt::Long::Configure(no_pass_through, auto_abbrev); > > This sets some global flags that the user may (optionally) set on the > command line. Other subroutines called after this perform a straight > GetOptions call > ie: GetOptions("a" => \$added, "e" => \$edited, "d" => \$deleted, > "c" => \$change); > > Well, with Ruby, if I try to have my entry code scan the command-line > arguments for a --log / -log argument, then when it sees say, a '-c' > instead, it raises an exception (which I can toss) since it's not part > of that GetoptLong argument array. > That's all fine and well, but unfortunately, it's also removed the > argument from ARGV at this point, so the next method that wants to scan > for >its< command-line arguments (perhaps to parse the -c) won't have > anything there. > Additionally, the exception thrown by GetoptLang doesn't even contain > information about what didn't match (or what was removed from ARGV), so > that I can add it back into argv. > > Any suggestions on how I can implement 'passthrough' command-line > arguments with Ruby? I use getoptlong alot, but I'm not quite sure I understand your problem. Can you provide a short example? -- Jim Freeze If only I had something clever to say for my comment... ~