Enhanced command-line interface.
This commit is contained in:
parent
c6676e5a07
commit
2bbd28c341
@ -11,30 +11,56 @@ int main(int argc, char **argv)
|
||||
|
||||
po::options_description description("Allowed options");
|
||||
description.add_options()
|
||||
("help,h", "display this help message")
|
||||
("input,i", po::value<std::string>(), "SAS input file");
|
||||
("help,h", "Display this help message.")
|
||||
("version,v", "Display version information.")
|
||||
("input,i", po::value<std::string>(), "Specify the SAS input file.");
|
||||
|
||||
po::positional_options_description positionalOptionsDescription;
|
||||
positionalOptionsDescription.add("input", -1);
|
||||
|
||||
po::variables_map variablesMap;
|
||||
po::store(po::command_line_parser(argc, argv)
|
||||
.options(description)
|
||||
.positional(positionalOptionsDescription)
|
||||
.run(),
|
||||
variablesMap);
|
||||
po::notify(variablesMap);
|
||||
|
||||
const auto printHelp =
|
||||
[&]()
|
||||
{
|
||||
std::cout << "Usage: plasp file [options]" << std::endl;
|
||||
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"))
|
||||
{
|
||||
std::cout << description;
|
||||
printHelp();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (variablesMap.count("version"))
|
||||
{
|
||||
std::cout << "plasp version 3.0.0" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (!variablesMap.count("input"))
|
||||
{
|
||||
std::cerr << "Error: No input file specified" << std::endl;
|
||||
std::cout << description;
|
||||
std::cerr << "Error: No input file specified" << std::endl << std::endl;
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@ -46,7 +72,9 @@ int main(int argc, char **argv)
|
||||
}
|
||||
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;
|
||||
|
Reference in New Issue
Block a user