Boost logo

Boost :

Subject: [boost] [program-options] Ticket #1132, multitoken() and zero_token()
From: Sascha Ochsenknecht (s.ochsenknecht_at_[hidden])
Date: 2009-10-09 05:39:28


Hello,

I would like to have an option which allows multi token but not multiple
occurrences of the option or at least a way to distinguish the occurrences:

E.g. something like:
   program.exe --option value1 value2

I tried the following:

1) desc.add_options()("option", value<string>()->multitoken(), "help");

With the above command line I get exception:
multiple values not allowed

2) desc.add_options()("option", value<vector<string> >(), "help");

Command line is parsed without error but only value1 is stored in the
vector -> ERROR, should report

3) desc.add_options()("option", value<vector<string> >()->multitoken(),
"help");

Command line is parsed without error both values are stored in the
vector, but
program.exe --option value1 --option value2 and
program.exe --option value1 value2
leads to the same vector contents.

With the current version it isn't possible to distinguish to occurrences
of a certain option and it is not possible to implement an option which
has the multitoken attribute but isn't allowed to occur several times.

I'm willing to work on a patch for this issue, but first I want to
discuss how to solve this, i.e. how the library should behave.

The problem is possibly that specifying a list or vector implies that an
option can occur multiple times.

I think maybe following solution could work:

1) desc.add_options()("option", value<vector<string> >(), "help");
     multiple occurrences of the option are allowed and pushed to the
vector but only one value per option occurrence (like it is implemented now)

2) desc.add_options()("option", value<vector<string> >()->multitoken(),
"help");
     multiple occurrences of the option are NOT allowed, the multiple
tokens/values are pushed to the vector

3) desc.add_options()("option", value<vector<vector<string> >
>()->multitoken(), "help");
     multiple occurrences of the option are allowed, the multiple
tokens/values are pushed to the inner vector

E.g. program.exe --option value1 value2 --option value3 --option value4
value5
This would result in the following storage sheme:
{ { value1, value2 } { value3 } { value4 value5 } }

I'm not sure if a could become a friend of this implementation ... but
it would work at least.

Another way would be to join the multitokens into a single string:
{ "value1 value2" "value3" "value4 value5" }
.. but this I don't like :-(.

What do you think?

Thanks & regards,
Sascha

PS: Is somebody working on ticket #1132 ??


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk