bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: option abbreviation exceptions


From: Eric Blake
Subject: Re: option abbreviation exceptions
Date: Sat, 10 Jan 2009 10:57:33 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.19) Gecko/20081209 Thunderbird/2.0.0.19 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Jim Meyering on 1/10/2009 10:48 AM:
> "[" feels like it should be the exception.
> I see treating --v like --version as a feature.  a typing saver.
> But with "[", it's good to minimize the number of strings that
> make it act differently.
> 
> Besides, why make everyone type it all out if there's no need?

Then maybe the better approach would be adding a parameter to
parse_long_options (or rather, creating a new function with an extra
parameter, and making parse_long_options default to calling it with the
parameter at 0, but make echo and [ call it with the parameter set to 1),
where having the parameter set controls whether --h is ignored (the
exception, for echo) or treated as an abbreviation (the rule, for things
like basename).

Or, for echo and [, we could skip parse_long_options altogether, and
hardcode this instead:

argc == 2 && (STREQ (argv[1], "--help") || STREQ (argv[1], "--version"))

> Then you don't have to "know" that a program accepts only
> --help and --version, and hence accepts no abbreviations,
> versus those that accept at least one more long option, which
> do provide the feature.
> 
> Also, it'd mean adding a third option would have
> the side effect of enabling --h and --v recognition.

That's kind of what happened with expr vs. factor.  Since
parse_long_options only recognizes exactly one argument as a long option,
adding another option already has a side effect:

$ src/factor --help | head -n1
Usage: src/factor [NUMBER]...
$ src/factor --help --version | head -n1
Usage: src/factor [NUMBER]...
$ src/expr --help | head -n1
Usage: src/expr EXPRESSION
$ src/expr --help --version | head -n1
src/expr: syntax error

expr currently uses parse_long_options, while factor does not; therefore
factor is able to handle --help --version while expr is not.

Maybe parse_long_options should be taught to recognize multiple options
that all match an abbreviation of --help/--version, rather than expecting
exactly one option?

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAklo4Y0ACgkQ84KuGfSFAYAkwwCcDzAlg75YBcUhuyPnkJ3oQKRb
REkAn0ZCjFU2Wpe76N93RdtH7e/bJ+b/
=zkiz
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]