Feature request: value pairs or tuples
maickrau opened this issue · comments
Hi, I'd like an option to input two values for a parameter and take them as an input. This would differ from std::vector
values in that the number of values given is constant. The use case I was trying to solve is optionally inputting a file with data and an another file with metadata describing the previous file, where the user can either include both or leave both out but including one without the other is invalid. Here's an example of what it would look like:
options.add_options()("file", "File and metadata", cxxopts::value<std::pair<std::string, std::string>>())
./main --file file1 metadata1
Ideally this could also be used with std::vector
options.add_options()("file", "File and metadata", cxxopts::value<std::vector<std::pair<std::string, std::string>>>())
./main --file file1 metadata1 --file file2 metadata2
and similarly with std::tuple
for more than 2 values.
The main difficulty would be parsing these together. It seems reasonable that you could split the values with a comma. Then I could support a pair or tuple and expect exactly the number of arguments in the type.
For example
cxxopts::value<std::tuple<int, int, int>>
would accept
--option 1,2,3