[getopt-sig] my current argument parser

Derek Harland derek@chocolate-fish.com
Wed, 13 Feb 2002 23:58:47 -0000


----- Original Message -----
From: "Russ Cox" <rsc@plan9.bell-labs.com>

Here are comments, you can rate their helpfulness !

> This illustrates all the important points:
>
> * arg is a generator that returns the next argument.
>   >>>The behavior of the generator depends on the behavior
>   of the body of your for loop.<<<  This is why you don't have
>   to tell the ArgParser about your options a priori.  If an option
>   has an argument, you call arg.nextarg() to fetch it.  (If you
>   want an option to have two arguments, call arg.nextarg twice.)

It might be nicer to be able instead to go a,b = arg.get(2),
if you know there are two values.  What about values = arg.consume() or
arg.getall() to consume all parameters to the next "argument" ?

ie given -I its iterative not optional -b wibble

you can go if o == 'I': words = args.consume() ??

> * Long options begin with -- and take arguments from an optional
>   ``=ARG'' suffix.  For example,
>   foo --long=bar

If we remove the optionality of long arguments then you can support
--long bar also.  Some people like this as it is at least consistent with
arguments to short options as well.  Personally I don't.

Des.