anthem/app/main.cpp

77 lines
1.6 KiB
C++
Raw Normal View History

2016-11-21 17:51:14 +01:00
#include <iostream>
#include <boost/program_options.hpp>
2016-11-22 03:15:52 +01:00
#include <anthem/Translation.h>
2016-11-21 17:51:14 +01:00
int main(int argc, char **argv)
{
namespace po = boost::program_options;
po::options_description description("Allowed options");
description.add_options()
2016-11-23 03:36:48 +01:00
("help,h", "Display this help message")
("version,v", "Display version information")
("input,i", po::value<std::vector<std::string>>(), "Input files");
2016-11-21 17:51:14 +01:00
po::positional_options_description positionalOptionsDescription;
positionalOptionsDescription.add("input", -1);
po::variables_map variablesMap;
const auto printHelp =
[&]()
{
std::cout << "Usage: anthem [files] [options]" << std::endl;
std::cout << "Translate ASP programs to the language of first-order theorem provers." << 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)
{
2016-11-22 03:15:52 +01:00
std::cerr << "error: " << e.what() << std::endl;
2016-11-21 17:51:14 +01:00
printHelp();
return EXIT_FAILURE;
}
if (variablesMap.count("help"))
{
printHelp();
return EXIT_SUCCESS;
}
if (variablesMap.count("version"))
{
std::cout << "anthem version 0.1.0-git" << std::endl;
return EXIT_SUCCESS;
}
2016-11-22 03:15:52 +01:00
try
{
if (variablesMap.count("input"))
{
const auto &inputFiles = variablesMap["input"].as<std::vector<std::string>>();
anthem::translate(inputFiles);
}
else
anthem::translate("std::cin", std::cin);
}
catch (const std::exception &e)
{
std::cerr << "error: " << e.what() << std::endl;
return EXIT_FAILURE;
}
2016-11-21 17:51:14 +01:00
return EXIT_SUCCESS;
}