From: Anton 'tony' Bangratz Date: 2006-05-31T01:03:56+09:00 Subject: Re: optparse "invalid option" problem --------------enigC06728446F6E444AF721852A Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Michael Keller wrote: > Hi, Hello, >=20 > 'optparse' seems to continue parsing even after the first invalid argum= ent. >=20 > example.rb: >=20 > require 'optparse' >=20 > ARGV.options do |opts| > opts.separator "Required:" > opts.on("-f", "--ffmpeg PATH", String, "ffmpeg's path") { |val| ffmpe= g > =3D val } > end >=20 > leftOver =3D ARGV.parse! > p leftOver >=20 >=20 >=20 >> example.rb -f ./ffmpeg Tool/to/call/from/example.rb >=20 > works as expected (leftOver contains "Tool/to/call/from/example.rb"), b= ut >=20 >=20 >> example.rb -f ./ffmpeg Tool/to/call/from/example.rb --toolsOption valu= e >=20 > raises "invalid option: --toolsOption" >=20 > instead of pushing "Tool/to/call/from/example.rb", "--toolsOption" and > "value" into leftOver >=20 That's how it's supposed to work: you can catch the error, or ... >=20 >=20 > Is there a way to tell optparse that everything after the first unknown= > argument is ignored and pushed into the resulting array? >=20 Not automatically, but you can try: example.rb -f ./ffmpeg Tool/to/call/from/example.rb -- --toolsOption\ val= ue =3D> ["Tool/to/call/from/example.rb", "--toolsOption", "value"] or you can quote the argument as a whole and split it later: example.rb -f ./ffmpeg Tool/to/call/from/example.rb "--toolsOption\ value= " =3D> ["Tool/to/call/from/example.rb --toolsOption value"] HTH, t. --=20 Anton Bangratz - Key ID 363474D1 - http://tony.twincode.net/ fortune(6): It would save me a lot of time if you just gave up and went mad now. --------------enigC06728446F6E444AF721852A Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iQEVAwUBRHxs3wgZMsE2NHTRAQJfowf/ZhnxODnjHYcBck2V8tsiQuRA1e4kV4+O UUJS5b8qocJzI7qVRYSAm4TR+Y7egxCrh6Ocyb8ErKESQxAibEce+EGfXO/lWt1E eFoh40Hh4K2Sf9MCt6Lc0C1RxF63M2kXWc/aoDXtlxLxlMEW6E9/rzFzDZrJ9XU3 DeDdq3Q2rzLpsUGjBV0l6NZtSwOoStlAS/bUX08GYa8nlltkBW7f9Dspe/DmuJdm ErSBSJsVW4v9P5fOFql1zUr233gY20H+CILqJB0y47dWVdJvMEe2feq+gkfDf92W zFoaKjM3l4ZRPVplrLPI4qVkTSM7H8vELt9HdF5OIV2C/j5l2p2uZQ== =PXP8 -----END PGP SIGNATURE----- --------------enigC06728446F6E444AF721852A--