Skip to content

Commit

Permalink
Enhanced command-line interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
pluehne committed May 24, 2016
1 parent c6676e5 commit 2bbd28c
Showing 1 changed file with 40 additions and 12 deletions.
52 changes: 40 additions & 12 deletions apps/plasp-app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down

0 comments on commit 2bbd28c

Please sign in to comment.