You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ArgumentParser::parse_args cannot be used multiple times and it would fail to detect missingness of mandatory positional args. Because of that I have to split tests testing if mandatory positional args work correctly into multiple tests. It is not very convenient.
The text was updated successfully, but these errors were encountered:
Can you give an example of code that does not work as you expect?
The following code allows me to parse a new set of arguments, adding to already found arguments. Notice in the third parse that program has not forgotten about --config from the second parse.
#include<argparse/argparse.hpp>
#include<iostream>
#include<string>intmain(int argc, constchar* argv[]) {
argparse::ArgumentParser program("test");
program.add_argument("--config");
std::string value;
try {
program.parse_args({"test"});
value = program.get("--config");
} catch (const std::logic_error& err) {
value = std::string("no argument");
}
std::cout << "1) config is '" << value << "'." << std::endl;
try {
program.parse_args({"test", "--config", "file.conf"});
value = program.get("--config");
} catch (const std::logic_error& err) {
value = std::string("no argument");
}
std::cout << "2) config is '" << value << "'." << std::endl;
try {
program.parse_args({"test"});
value = program.get("--config");
} catch (const std::logic_error& err) {
value = std::string("no argument");
}
std::cout << "3) config is '" << value << "'." << std::endl;
}
$ ./reuse-parse_args
1) config is 'no argument'.
2) config is 'file.conf'.
3) config is 'file.conf'.
ArgumentParser::parse_args
cannot be used multiple times and it would fail to detect missingness of mandatory positional args. Because of that I have to split tests testing if mandatory positional args work correctly into multiple tests. It is not very convenient.The text was updated successfully, but these errors were encountered: