Description
Howdy,
I am trying to build a CLI application with an option that both expects multiple values, and can be given multiple times, e.g.:
myapp --option 1 2 3 --option 4 5 6
I want the values to be aggregated into a vector of vectors, so am using the following
code:
std::vector<std::vector<int>> option;
app.add_option(
"--option",
option,
"Vector of vectors");
This works just fine when the --option
values are specified at the command-line - I end up with a vector containing two vectors, which contain 1 2 3
and 4 5 6
respectively.
However there appears to be an issue when I try to specify the options in a configuration file, enabled via app.set_config("--config")
. If I create a config.ini
file with the following:
option = 1 2 3
option = 4 5 6
and run myapp --config config.ini
, I end up with a vector which contains just one vector, containing 1 2 3 4 5 6
.
Here is a minimal example which reproduces the issue:
#include <iostream>
#include <vector>
#include "CLI/CLI.hpp"
int main(int argc, char * argv[]) {
CLI::App app{"MyApp"};
std::vector<std::vector<int>> option;
app.add_option(
"--option",
option,
"Container of containers");
app.set_config("--config");
CLI11_PARSE(app, argc, argv);
std::cout << "CLI11 version "
<< CLI11_VERSION_MAJOR << "."
<< CLI11_VERSION_MINOR << "."
<< CLI11_VERSION_PATCH << std::endl;
std::cout << "Value for --option" << std::endl;
for (auto &vec : option) {
for (auto &val : vec) {
std::cout << val << " ";
}
std::cout << std::endl;
}
}
When specifying the values at the command-line:
./myapp --option 1 2 3 --option 4 5 6
I get the expected result:
CLI11 version 2.4.2
Value for --option
1 2 3
4 5 6
However, when I use a config file:
echo "option = 1 2 3" > config.ini
echo "option = 4 5 6" >> config.ini
./myapp --config config.ini
I get:
CLI11 version 2.4.2
Value for --option
1 2 3 4 5 6
Thanks!