Exemple #1
0
void CmdLineParams::Parse()
{
	desc.add(all);
	all.add_options()("input-file", po::value<std::string>(), "input file");
	po::positional_options_description p;
	p.add("input-file", 1);

	try {
		po::parsed_options parsed = po::command_line_parser(argc, argv).options(all).positional(p).allow_unregistered().run();
		po::store(parsed, vm);
		po::notify(vm);

		std::vector<std::string> unrecognized = po::collect_unrecognized(parsed.options, po::exclude_positional);
		if (!unrecognized.empty())
			throw unrecognized_option("unrecognized option '" + unrecognized[0] + "'");
	} catch(const boost::program_options::too_many_positional_options_error& err) {
		throw unrecognized_option("too many unnamed cmdline input options (forgot to quote filepath?)");
	}
}
Exemple #2
0
void CmdLineParams::Parse()
{
	desc.add(all);
	all.add_options()("input-file", po::value<std::string>(), "input file");
	po::positional_options_description p;
	p.add("input-file", 1);

	po::parsed_options parsed = po::command_line_parser(argc, argv).options(all).positional(p).allow_unregistered().run();
	po::store(parsed, vm);
	po::notify(vm);

	std::vector<std::string> unrecognized = po::collect_unrecognized(parsed.options, po::exclude_positional);
	if (!unrecognized.empty())
		throw unrecognized_option("unrecognized option '" + unrecognized[0] + "'");
}