develooper Front page | perl.perl5.porters | Postings from April 2003

Re: [PATCH 5.8.1 @19053] Getopt::Std

Thread Previous | Thread Next
Johan Vromans
April 4, 2003 07:07
Re: [PATCH 5.8.1 @19053] Getopt::Std
Message ID:
Ilya Zakharevich <ilya@Math.Berkeley.EDU> writes:

> The only purpose of $EXIT_ON_HELP_VERSION is the backward
> compatibility, so one cannot make an arbitrary script exit early by
> providing --help option.

The more I think about this, the more I start worrying about semantics
and backward compatibility.

The common semantics (GNU-style) are:

  --help      display this help and exit
  --version   output version information and exit

Focusing on --version (the situation is similar for --help):
Currently, an ordinary script will bail out with a message:

 % foo --version
 Unrecognized switch: --version  (-h will show valid options).
 Exit 255

With the new Getopt::Std, the same script will behave differently:

 % foo --version
 foo version 1.24 calling Getopt::Std::getopts (version 1.04),
 running under Perl version 5.8.0.
 No args supplied, using current directory.
 Removing all files... Done.
 Exit 0

This is bad, since either the script does not understand --version and
bails out, or it handles --version appropriately and exits after
showing the version message. In either case, no processing is done.

To avoid nasty surprises, getopts _must_ exit by default after
processing --help/version, making the $EXIT_ON_HELP_VERSION facility

For Getopt::Long, I'm considering to enable the new functionality only
when the correct version is required/used. So "use Getopt::Long" would
run in compatibility mode, while "use Getopt::Long 2.34" (or whatever
version implements the new features) would enable these.
Getopt::Std could do the same, I assume.

-- Johan

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About