Does boost :: program_options support one of several alternatives?

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?

+6
source share
1 answer

The program_options validator does not support parameter interdependencies (including negative ones).

Probably what you are doing right now is actually the best option.

+4
source

All Articles