2017-10-13 17:12:33 +02:00
|
|
|
#include <plasp-app/OptionGroups.h>
|
2017-09-08 21:26:38 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2017-10-13 17:12:33 +02:00
|
|
|
// Option Groups
|
2017-09-08 21:26:38 +02:00
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-14 02:04:13 +02:00
|
|
|
// Nasty workaround needed for GCC prior to version 7
|
|
|
|
constexpr decltype(OptionGroupBasic::Name) OptionGroupBasic::Name;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-13 17:12:33 +02:00
|
|
|
void OptionGroupBasic::addTo(cxxopts::Options &options)
|
2017-09-08 21:26:38 +02:00
|
|
|
{
|
2017-10-13 18:09:15 +02:00
|
|
|
options.add_options(Name)
|
2017-10-13 17:12:33 +02:00
|
|
|
("h,help", "Display this help message")
|
|
|
|
("v,version", "Display version information")
|
|
|
|
("warnings-as-errors", "Treat warnings as errors");
|
2017-09-08 21:26:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-13 17:12:33 +02:00
|
|
|
void OptionGroupBasic::parse(cxxopts::Options &options)
|
2017-09-08 21:26:38 +02:00
|
|
|
{
|
2017-10-13 17:12:33 +02:00
|
|
|
help = options["help"].as<bool>();
|
|
|
|
version = options["version"].as<bool>();
|
|
|
|
warningsAsErrors = options["warnings-as-errors"].as<bool>();
|
2017-09-08 21:26:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-14 02:04:13 +02:00
|
|
|
// Nasty workaround needed for GCC prior to version 7
|
|
|
|
constexpr decltype(OptionGroupOutput::Name) OptionGroupOutput::Name;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-13 17:12:33 +02:00
|
|
|
void OptionGroupOutput::addTo(cxxopts::Options &options)
|
2017-09-08 21:26:38 +02:00
|
|
|
{
|
2017-10-13 18:09:15 +02:00
|
|
|
options.add_options(Name)
|
2017-10-13 17:12:33 +02:00
|
|
|
("color", "Colorize output (always, never, auto)", cxxopts::value<std::string>()->default_value("auto"))
|
|
|
|
("p,log-priority", "Log messages starting from this priority (debug, info, warning, error)", cxxopts::value<std::string>()->default_value("info"));
|
2017-09-08 21:26:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-13 17:12:33 +02:00
|
|
|
void OptionGroupOutput::parse(cxxopts::Options &options)
|
2017-09-08 21:26:38 +02:00
|
|
|
{
|
2017-10-13 17:12:33 +02:00
|
|
|
const auto colorPolicyString = options["color"].as<std::string>();
|
|
|
|
|
|
|
|
if (colorPolicyString == "auto")
|
|
|
|
colorPolicy = colorlog::ColorStream::ColorPolicy::Auto;
|
|
|
|
else if (colorPolicyString == "never")
|
|
|
|
colorPolicy = colorlog::ColorStream::ColorPolicy::Never;
|
|
|
|
else if (colorPolicyString == "always")
|
|
|
|
colorPolicy = colorlog::ColorStream::ColorPolicy::Always;
|
2017-09-08 21:26:38 +02:00
|
|
|
else
|
2017-10-13 17:12:33 +02:00
|
|
|
throw OptionException("unknown color policy “" + colorPolicyString + "”");
|
2017-09-08 21:26:38 +02:00
|
|
|
|
2017-10-12 17:18:00 +02:00
|
|
|
const auto logPriorityString = options["log-priority"].as<std::string>();
|
2017-09-08 21:26:38 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-10-13 17:12:33 +02:00
|
|
|
logPriority = colorlog::priorityFromName(logPriorityString.c_str());
|
2017-09-08 21:26:38 +02:00
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
throw OptionException(e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-14 02:04:13 +02:00
|
|
|
// Nasty workaround needed for GCC prior to version 7
|
|
|
|
constexpr decltype(OptionGroupParser::Name) OptionGroupParser::Name;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-13 17:12:33 +02:00
|
|
|
void OptionGroupParser::addTo(cxxopts::Options &options)
|
2017-09-08 21:26:38 +02:00
|
|
|
{
|
2017-10-13 18:09:15 +02:00
|
|
|
options.add_options(Name)
|
2017-10-13 17:12:33 +02:00
|
|
|
("i,input", "Input files (in PDDL or SAS format)", cxxopts::value<std::vector<std::string>>())
|
|
|
|
("parsing-mode", "Parsing mode (strict, compatibility)", cxxopts::value<std::string>()->default_value("strict"))
|
|
|
|
("l,language", "Input language (pddl, sas, auto)", cxxopts::value<std::string>()->default_value("auto"));
|
|
|
|
options.parse_positional("input");
|
2017-10-14 01:20:26 +02:00
|
|
|
options.positional_help("[<input_file...>]");
|
2017-10-13 17:12:33 +02:00
|
|
|
}
|
2017-09-08 21:26:38 +02:00
|
|
|
|
2017-10-13 17:12:33 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void OptionGroupParser::parse(cxxopts::Options &options)
|
|
|
|
{
|
2017-10-12 17:18:00 +02:00
|
|
|
const auto parsingModeString = options["parsing-mode"].as<std::string>();
|
2017-09-08 21:26:38 +02:00
|
|
|
|
|
|
|
if (parsingModeString == "compatibility")
|
2017-10-13 17:12:33 +02:00
|
|
|
parsingMode = pddl::Mode::Compatibility;
|
2017-09-08 21:26:38 +02:00
|
|
|
else if (parsingModeString != "strict")
|
|
|
|
throw OptionException("unknown parsing mode “" + parsingModeString + "”");
|
|
|
|
|
2017-10-12 17:18:00 +02:00
|
|
|
if (options.count("input"))
|
2017-10-13 17:12:33 +02:00
|
|
|
inputFiles = options["input"].as<std::vector<std::string>>();
|
2017-09-08 21:26:38 +02:00
|
|
|
|
2017-10-12 17:18:00 +02:00
|
|
|
const auto languageName = options["language"].as<std::string>();
|
2017-10-13 17:12:33 +02:00
|
|
|
language = plasp::Language::fromString(languageName);
|
2017-09-08 21:26:38 +02:00
|
|
|
|
2017-10-13 17:12:33 +02:00
|
|
|
if (language == plasp::Language::Type::Unknown)
|
2017-09-08 21:26:38 +02:00
|
|
|
throw OptionException("unknown input language “" + languageName + "”");
|
|
|
|
}
|