Mutually exclusive switches in getopt?

Andrej Mitrovic none at none.none
Sun May 29 21:43:36 PDT 2011


I don't see this option in getopt, is it there?

e.g. If I want to disallow passing "--loud" and "--quite" at the same time. 
I can understand it would be difficult to implement this with getopt's current API.

A limited form of this is possible to do inline via a delegate. For example:

bool quiet, loud;

getopt
(
    args, 
    "quiet", { enforce(!loud); quiet = true; },
    "loud",  { enforce(!quiet); loud  = true; },
);

However that scales poorly with more than two arguments, and especially if they're of a different type.


More information about the Digitalmars-d-learn mailing list