boost::program_options question - enabling multiple usage of the same switch

Hi, This question was originally brought up here: http://lists.boost.org/boost-users/2006/08/21633.php but unfortunately was not answered. What I basically want to do is to enable something like running $ myprog -v -v -v Where -v is some Boolean switch. Thanks, -Sergey --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

Khaikin, Sergey wrote:
Hi,
This question was originally brought up here:
http://lists.boost.org/boost-users/2006/08/21633.php
but unfortunately was not answered. What I basically want to do is to enable something like running
$ myprog -v -v -v
Where -v is some Boolean switch.
Boolean? What would be the semantics of multiple occurences? If you want integer variable that is incremented by 1 for each occurrence, then I think this is entirely syntax matter, and probably is best handled by taking vector<option> returned by parse_command_line, finding all -v occurences, and merging them into a single option, with a value equal to the number of occurrences. There is no built-in way to do this. - Volodya

Hi Volodya, Semantics of multiple occurrences would be "ignore all the occurrences but one and assume the switch value is true". So it's pretty much a syntactic issue. Maybe if I describe the use case the need for this syntax will become clearer. In my application, there is some external tool that generates command line for my tool. In some cases, it may generate Boolean switches more than one time and I need to support this "silently" instead of throwing "multiple_occurences" exception. Do you have any kind of workaround in mind ? (well, except using external script to preprocess the command line which makes the flow cumbersome). Thanks, Sergey -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Vladimir Prus Sent: Tuesday, October 07, 2008 5:06 PM To: boost@lists.boost.org Subject: Re: [boost] boost::program_options question - enabling multipleusage of the same switch Khaikin, Sergey wrote:
Hi,
This question was originally brought up here:
http://lists.boost.org/boost-users/2006/08/21633.php
but unfortunately was not answered. What I basically want to do is to enable something like running
$ myprog -v -v -v
Where -v is some Boolean switch.
Boolean? What would be the semantics of multiple occurences? If you want integer variable that is incremented by 1 for each occurrence, then I think this is entirely syntax matter, and probably is best handled by taking vector<option> returned by parse_command_line, finding all -v occurences, and merging them into a single option, with a value equal to the number of occurrences. There is no built-in way to do this. - Volodya _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
participants (2)
-
Khaikin, Sergey
-
Vladimir Prus