[Mono-dev] Program Option Parsing Library

Jonathan Pryor jonpryor at vt.edu
Thu Jan 10 16:00:23 EST 2008


On Thu, 2008-01-10 at 11:57 -0800, Jay Logue wrote:
> So, what happens if I pass new string[] { "--foo", "--bar" } as 
> arguments where --foo and --bar are declared as options and --foo takes 
> a value?  And what does Getopt::Long do in this case?

There's a test for this -- see Test.CheckExceptions().  An
InvalidOperationException would be generated if --foo requires a value
and --bar is registered (i.e. "-a -a" throws).  If --bar is NOT
registered, then --foo gets the value --bar.

The same is true if --foo were a boolean and --bar required a value --
an InvalidOperationException would be thrown as --bar is missing a
value.

As for what Getopt::Long does...  "--foo --bar" sets "--bar" as the
value of the --foo argument.  "--bar --foo" (i.e. no argument for --foo)
generates the output:

	Option foo requires an argument

I'm conflicted as to which is the better behavior.

 - Jon





More information about the Mono-devel-list mailing list