Eric Wilhelm <[EMAIL PROTECTED]> writes:

> I'm not super happy with the array-reference interface (it assumes a
> lot and lines tend to need a lot of re-wrapping), but it gets
> everything into one place rather than scattered about and allows the
> variables to tell the user their default values (even solving the
> side-effect that Johan pointed out.) It also allows you to maintain
> an order, which a hash wouldn't.

I have experimented with:

  GetOptions("create|c?create a new archive" => \$create,
             "color=i{3}(0..255)?color components" => [EMAIL PROTECTED],
             ...
            );

The user-friendlyness dropped quickly with the power added.

The ultimate solution would be to have individual objects for each
option, like I once tried with the (still stillborn) Getopt::Long TNG:

  my %opt = ();
  my $p = new Getopt::Long
                  -Config => [qw(noignorecase bundling)],
                  -Linkage => \%opt;

  $p->add (new Getopt::Long::Option
           -Name => 'concatenate',
           -Aliases => ['catenate','A'],
           -Help => 'append tar files to an archive');
  $p->add (new Getopt::Long::Option
           -Name => 'create',
           -Aliases => ['c'],
           -Help => 'create a new archive');
  $p->add (new Getopt::Long::IntOption
           -Name => 'block-size',
           -Aliases => ['b'],
           -Help => 'block size of <n>x512 bytes (default <n>=20)');
  $p->add (new Getopt::Long::StringOption
           -Name => 'directory',
           -Aliases => ['C'],
           -Help => 'change to directory <dir>');
  unless ( $p->parse ) {
     $p->usage (-indent => 4, -hang => 12, -width => 60,
                -longprefix => "--", -shortprefix => "-");
  }

This would produce:

    --concatenate  --catenate  -C
            append tar files to an archive
    --create -c
            create a new archive
    --block-size=<n>  -B
            block size of <n>x512 bytes (default <n>=20)
    --directory=<dir>  -C
            change to directory <dir>

But then you'll want other texts, and empty lines, and so on. 

  Usage: album [options] [ directory ]

    Album:
      --info XXX          description file, default "info.dat" (if it exists)
      --title XXX         album title, default "Photos"

    Index:
      --cols NN           number of columns per page, default 4
      --rows NN           number of rows per page, default 3
      --thumbsize NNN     the max size of thumbnail images, default 200
      --captions XXX      f: filename s: size c: description t: tag

There's always a next hop...

-- Johan

Reply via email to