Enhanced command-line interface.

This commit is contained in:
Patrick Lühne 2016-05-24 16:24:37 +02:00
parent c6676e5a07
commit 2bbd28c341

View File

@ -11,30 +11,56 @@ int main(int argc, char **argv)
po::options_description description("Allowed options"); po::options_description description("Allowed options");
description.add_options() description.add_options()
("help,h", "display this help message") ("help,h", "Display this help message.")
("input,i", po::value<std::string>(), "SAS input file"); ("version,v", "Display version information.")
("input,i", po::value<std::string>(), "Specify the SAS input file.");
po::positional_options_description positionalOptionsDescription; po::positional_options_description positionalOptionsDescription;
positionalOptionsDescription.add("input", -1); positionalOptionsDescription.add("input", -1);
po::variables_map variablesMap; po::variables_map variablesMap;
po::store(po::command_line_parser(argc, argv)
.options(description) const auto printHelp =
.positional(positionalOptionsDescription) [&]()
.run(), {
variablesMap); std::cout << "Usage: plasp file [options]" << std::endl;
po::notify(variablesMap); std::cout << "Translate PDDL instances to ASP facts." << std::endl << std::endl;
std::cout << description;
};
try
{
po::store(po::command_line_parser(argc, argv)
.options(description)
.positional(positionalOptionsDescription)
.run(),
variablesMap);
po::notify(variablesMap);
}
catch (const po::error &e)
{
std::cerr << "Error: " << e.what() << std::endl << std::endl;
printHelp();
return EXIT_FAILURE;
}
if (variablesMap.count("help")) if (variablesMap.count("help"))
{ {
std::cout << description; printHelp();
return EXIT_SUCCESS;
}
if (variablesMap.count("version"))
{
std::cout << "plasp version 3.0.0" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
if (!variablesMap.count("input")) if (!variablesMap.count("input"))
{ {
std::cerr << "Error: No input file specified" << std::endl; std::cerr << "Error: No input file specified" << std::endl << std::endl;
std::cout << description; printHelp();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -46,7 +72,9 @@ int main(int argc, char **argv)
} }
catch (const std::exception &e) catch (const std::exception &e)
{ {
std::cerr << "Error: " << e.what() << std::endl; std::cerr << "Error: " << e.what() << std::endl << std::endl;
printHelp();
return EXIT_FAILURE;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;