Proposal: fix for getOpt (missing feature)

Proposal: to fix a missing feature in the Haskell implementation of GNU getOpt. Currently, long option names _must_ have two dashes (e.g. --foo), whereas this patch permits a single dash (e.g. -foo) where there is no short option name to be confused with it (e.g. -f).

Hi Malcolm,
Doesn't -foo currently mean -f -o -o ? In that case, this will change
the behaviour.
Thanks
Neil
On 6/25/07, Malcolm Wallace
Proposal: to fix a missing feature in the Haskell implementation of GNU getOpt. Currently, long option names _must_ have two dashes (e.g. --foo), whereas this patch permits a single dash (e.g. -foo) where there is no short option name to be confused with it (e.g. -f).
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On Mon, 25 Jun 2007, Bryan O'Sullivan wrote:
Neil Mitchell wrote:
Doesn't -foo currently mean -f -o -o ? In that case, this will change the behaviour.
Malcolm's change only affects the situation where "-foo" can unambiguously be interpreted as "--foo", because there doesn't exist a "-f" short option.
I think the program user should be encouraged to use two dashes for the 'foo' option, in order to allow the programmer to add options -f and -o later without the risk of breaking existing scripts.

On 25 jun 2007, at 22.23, Malcolm Wallace wrote:
Proposal: to fix a missing feature in the Haskell implementation of GNU getOpt. Currently, long option names _must_ have two dashes (e.g. --foo), whereas this patch permits a single dash (e.g. -foo) where there is no short option name to be confused with it (e.g. -f).
Are, you sure this is a good idea? What if options are passed through, or the -f option is later added? Then users have to change there scripts, maxefiles, etc. that use these options. I don't think this scales well. /Thomas

me:
Currently, long option names _must_ have two dashes (e.g. --foo), whereas this patch permits a single dash (e.g. -foo) where there is no short option name to be confused with it (e.g. -f).
nominolo:
Are, you sure this is a good idea? What if options are passed through, or the -f option is later added? Then users have to change there scripts, maxefiles, etc. that use these options. I don't think this scales well.
It is the behaviour of GNU GetOpt, which is very widely used and understood. The proposal is merely that the Haskell implementation should match the de facto standard in this area. (It even originally contained a comment stating that it was deficient here!) I believe there are a large number of people who use unix-style commandlines who would expect this behaviour. lemming:
I think the program user should be encouraged to use two dashes for the 'foo' option, in order to allow the programmer to add options -f and -o later without the risk of breaking existing scripts.
Sure, and all the usage + error messages generated by GetOpt mention only the two-dash form, as a way of encouraging forward compatibility. Regards, Malcolm

It is the behaviour of GNU GetOpt, which is very widely used and understood.
No, it isn't. At least, it's not the default. The GNU libc manual encourages the use of getopt_long(). It also provides an alternative called getopt_long_only() for programs that want to be backward compatible. Here's the relevant bit from the libc manual: Since long option names were used before before the `getopt_long' options was invented there are program interfaces which require programs to recognize options like `-option value' instead of `--option value'. To enable these programs to use the GNU getopt functionality there is one more function available. -- Function: int getopt_long_only (int ARGC, char *const *ARGV, const char *SHORTOPTS, const struct option *LONGOPTS, int *INDEXPTR) The `getopt_long_only' function is equivalent to the `getopt_long' function but it allows to specify the user of the application to pass long options with only `-' instead of `--'. The `--' prefix is still recognized but instead of looking through the short options if a `-' is seen it is first tried whether this parameter names a long option. If not, it is parsed as a short option. Assuming `getopt_long_only' is used starting an application with app -foo the `getopt_long_only' will first look for a long option named `foo'. If this is not found, the short options `f', `o', and again `o' are recognized. -- /jaap
participants (6)
-
Bryan O'Sullivan
-
Henning Thielemann
-
Jaap Weel
-
Malcolm Wallace
-
Neil Mitchell
-
Thomas Schilling