Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

mutually exclusive options?

Help
2007-10-27
2013-05-28
  • Bryn Jeffries
    Bryn Jeffries
    2007-10-27

    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
      2007-10-29

      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
        2007-11-04

        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().