I've posted the following question on SO, but I guess boost::program_options
can't help me here:
I have options
--foo
(short form-f
) and--bar
that need special treatment, they are repeatable and order should matter. So, for the following:program --foo 1 --z -f 2 --bar 3 --x --foo 4
I'd like to range a key value map being able to construct
[("foo", 1), ("foo", 2), ("bar", 3), ("foo", 4)]
.Please notice the order of this array of tuples, it's the same as that in the command line. I've discarded non-important options in the array, but they may be present in the command line nonetheless.
It seems the sole way to allow repeatable options with
boost::program_options
is callingcomposing()
for any given option, but then, since each will store all their values in a vector, I lose the order I need for interlacing options.So, can
boost::program_options
help with this?
source: https://stackoverflow.com/questions/36973114/
I'm looking for a library that allows me to range through the parsed options (if possible with their names normalized to their long or short names) in the order it's given in the command line because such order is important for me.
program_options
can give you everything it didn't parse itself as avector<string>
. In fact, I use this ugly piece of code to put it into a key-value map in a project I'm working on, and it shouldn't be difficult to adapt to what you need I guess.boost::program_options::collect_unrecognized()
. Although I will say you probably shouldn't be assuming order for command-line options, i.e. the problem is more in the fact that you're trying to do this IMO.matrix_product_program --matrix="{...}" --matrix="{...}" --matrix="{...}"
. Any problem with having to fit this situation with a solution as explained?boost::program_options
is interesting.