2017-09-08 21:26:38 +02:00
|
|
|
#include <plasp-app/CommonOptions.h>
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Common Options
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-12 17:18:00 +02:00
|
|
|
void addBasicOptions(cxxopts::Options &options)
|
2017-09-08 21:26:38 +02:00
|
|
|
{
|
2017-10-12 17:18:00 +02:00
|
|
|
options.add_options("basic")
|
|
|
|
("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-12 17:18:00 +02:00
|
|
|
void addOutputOptions(cxxopts::Options &options)
|
2017-09-08 21:26:38 +02:00
|
|
|
{
|
2017-10-12 17:18:00 +02:00
|
|
|
options.add_options("output")
|
|
|
|
("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-12 17:18:00 +02:00
|
|
|
void addParserOptions(cxxopts::Options &options)
|
2017-09-08 21:26:38 +02:00
|
|
|
{
|
2017-10-12 17:18:00 +02:00
|
|
|
options.add_options("parser")
|
|
|
|
("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-09-08 21:26:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-12 17:18:00 +02:00
|
|
|
BasicOptions parseBasicOptions(cxxopts::Options &options)
|
2017-09-08 21:26:38 +02:00
|
|
|
{
|
|
|
|
BasicOptions basicOptions;
|
|
|
|
|
2017-10-12 17:18:00 +02:00
|
|
|
basicOptions.help = options["help"].as<bool>();
|
|
|
|
basicOptions.version = options["version"].as<bool>();
|
|
|
|
basicOptions.warningsAsErrors = options["warnings-as-errors"].as<bool>();
|
2017-09-08 21:26:38 +02:00
|
|
|
|
|
|
|
return basicOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-12 17:18:00 +02:00
|
|
|
OutputOptions parseOutputOptions(cxxopts::Options &options)
|
2017-09-08 21:26:38 +02:00
|
|
|
{
|
|
|
|
OutputOptions outputOptions;
|
|
|
|
|
2017-10-12 17:18:00 +02:00
|
|
|
const auto colorPolicy = options["color"].as<std::string>();
|
2017-09-08 21:26:38 +02:00
|
|
|
|
|
|
|
if (colorPolicy == "auto")
|
|
|
|
outputOptions.colorPolicy = colorlog::ColorStream::ColorPolicy::Auto;
|
|
|
|
else if (colorPolicy == "never")
|
|
|
|
outputOptions.colorPolicy = colorlog::ColorStream::ColorPolicy::Never;
|
|
|
|
else if (colorPolicy == "always")
|
|
|
|
outputOptions.colorPolicy = colorlog::ColorStream::ColorPolicy::Always;
|
|
|
|
else
|
|
|
|
throw OptionException("unknown color policy “" + colorPolicy + "”");
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
outputOptions.logPriority = colorlog::priorityFromName(logPriorityString.c_str());
|
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
throw OptionException(e.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
return outputOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-12 17:18:00 +02:00
|
|
|
ParserOptions parseParserOptions(cxxopts::Options &options)
|
2017-09-08 21:26:38 +02:00
|
|
|
{
|
|
|
|
ParserOptions parserOptions;
|
|
|
|
|
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")
|
|
|
|
parserOptions.parsingMode = pddl::Mode::Compatibility;
|
|
|
|
else if (parsingModeString != "strict")
|
|
|
|
throw OptionException("unknown parsing mode “" + parsingModeString + "”");
|
|
|
|
|
2017-10-12 17:18:00 +02:00
|
|
|
if (options.count("input"))
|
|
|
|
parserOptions.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-09-08 21:26:38 +02:00
|
|
|
parserOptions.language = plasp::Language::fromString(languageName);
|
|
|
|
|
|
|
|
if (parserOptions.language == plasp::Language::Type::Unknown)
|
|
|
|
throw OptionException("unknown input language “" + languageName + "”");
|
|
|
|
|
|
|
|
return parserOptions;
|
|
|
|
}
|