mutually exclusive options?

  • Bryn Jeffries
    Bryn Jeffries

    What is the best way to implement mutually exclusive options? If I use addXor to add two or more switched, it seems that the user is required to supply one switch. I would like the user to specify either -b, -t, or neither (-t is the default, so it isn't required).

    • Mike Smoot
      Mike Smoot

      You're correct that xorAdd forces one arg or the other to be present. 

      However, given the scenario that you describe above, you really only need one option, -b, since -t is already the default.  This would work for any number of options, you'll just have 1 less switch than the number of options.

      • Daniel Aarno
        Daniel Aarno

        You can always manually assert that only one options was given, for example if you want the two options to make it more explicit which is used. One way to do this would be to make a function that adds the option to the CmdLine and to a vector, then count the the number of set options (see Arg::isSet) in this vector and assert that it is less then two. Obviously if you only have two options you can simply check that both does not return true from isSet().