I use boost :: program_options to specify the arguments for my C ++ application. Is there a way to indicate that one argument is required from a set of alternatives?
<application> [--one int-value1 | --two string-value2 | --three]
In the above example, the user must pass one of the alternatives: --one , --two or --three .
I could do it manually, but hopefully there is a built-in mechanism instead:
#include <boost/program_options.hpp> namespace po = boost::program_options; int main(int argc, char *argv[]) { po::options_description options; int band; std::string titles_path; options.add_options() ("one", po::value<int>(&band)->default_value(1)) ("two", po::value<std::string>(&titles_path)) ("three"); po::variables_map vm; po::store(po::parse_command_line(argc, argv, options), vm); if (1 != (vm.count("one") + vm.count("two") + vm.count("three"))) { std::cerr << options << std::endl; return -11; } return 0; }
Is there a better way to do this with boost options?
source share