patrick
/
plasp
Archived
1
0
Fork 0

Implemented new command-line options replacing --warning-level.

This commit is contained in:
Patrick Lühne 2016-12-01 17:18:58 +01:00
parent cfce6b1bbd
commit 9e1cdaaa51
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
4 changed files with 48 additions and 22 deletions

View File

@ -6,6 +6,8 @@ Features:
* extended PDDL support (`imply` expressions)
* improved command-line interface
* new command-line option `--log-level` to control which status messages should be shown
* new command-line option `--warnings-as-errors` to abort program execution upon warnings (replaces `--warning-level`)
## 3.0.3 (2016-09-02)

View File

@ -16,14 +16,17 @@ int main(int argc, char **argv)
{
namespace po = boost::program_options;
bool warningsAsErrors;
po::options_description description("Allowed options");
description.add_options()
("help,h", "Display this help message")
("version,v", "Display version information")
("input,i", po::value<std::vector<std::string>>(), "Input files (in PDDL or SAS format)")
("language,l", po::value<std::string>()->default_value("auto"), "Input language (pddl, sas, auto)")
("warning-level", po::value<std::string>()->default_value("show"), "Show warnings (show), treat them as errors (error), or ignore them (ignore)")
("color", po::value<std::string>()->default_value("auto"), "Colorize output (always, never, auto)");
("color", po::value<std::string>()->default_value("auto"), "Colorize output (always, never, auto)")
("log-priority,p", po::value<std::string>()->default_value("warning"), "Log messages starting from this priority (debug, info, warning, error)")
("warnings-as-errors", po::bool_switch(&warningsAsErrors), "Treat warnings as errors");
po::positional_options_description positionalOptionsDescription;
positionalOptionsDescription.add("input", -1);
@ -70,22 +73,8 @@ int main(int argc, char **argv)
return EXIT_SUCCESS;
}
const auto warningLevel = variablesMap["warning-level"].as<std::string>();
// TODO: reimplement
/*if (warningLevel == "error")
logger.setWarningLevel(plasp::output::Logger::WarningLevel::Error);
else if (warningLevel == "ignore")
logger.setWarningLevel(plasp::output::Logger::WarningLevel::Ignore);
else if (warningLevel == "show")
logger.setWarningLevel(plasp::output::Logger::WarningLevel::Show);
else
{
logger.log(plasp::output::Priority::Error, "unknown warning level “" + warningLevel + "");
std::cout << std::endl;
printHelp();
return EXIT_FAILURE;
}*/
if (warningsAsErrors)
logger.setAbortPriority(plasp::output::Priority::Warning);
const auto colorPolicy = variablesMap["color"].as<std::string>();
@ -103,6 +92,21 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
const auto logPriorityString = variablesMap["log-priority"].as<std::string>();
try
{
const auto logPriority = plasp::output::priorityFromName(logPriorityString.c_str());
logger.setLogPriority(logPriority);
}
catch (const std::exception &e)
{
logger.log(plasp::output::Priority::Error, ("unknown log priorty “" + logPriorityString + "").c_str());
logger.errorStream() << std::endl;
printHelp();
return EXIT_FAILURE;
}
try
{
plasp::input::Parser<plasp::input::CaseInsensitiveParserPolicy> parser;

View File

@ -30,8 +30,10 @@ class Logger
ColorStream &outputStream();
ColorStream &errorStream();
// The level from which on messages should be printed
// The priority from which on messages should be printed
void setLogPriority(Priority logPriority);
// Messages with this priority (or higher) will terminate the programs execution
void setAbortPriority(Priority abortPriority);
void setColorPolicy(ColorStream::ColorPolicy colorPolicy);
void log(Priority priority, const char *message);
@ -44,6 +46,7 @@ class Logger
ColorStream m_errorStream;
Priority m_logPriority;
Priority m_abortPriority;
};
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -57,7 +57,8 @@ Logger::Logger(ColorStream &&outputStream)
Logger::Logger(ColorStream &&outputStream, ColorStream &&errorStream)
: m_outputStream{outputStream},
m_errorStream{errorStream},
m_logPriority{Priority::Warning}
m_logPriority{Priority::Warning},
m_abortPriority{Priority::Error}
{
}
@ -66,7 +67,8 @@ Logger::Logger(ColorStream &&outputStream, ColorStream &&errorStream)
Logger::Logger(Logger &&other)
: m_outputStream{std::move(other.m_outputStream)},
m_errorStream{std::move(other.m_errorStream)},
m_logPriority{other.m_logPriority}
m_logPriority{other.m_logPriority},
m_abortPriority{other.m_abortPriority}
{
}
@ -102,6 +104,13 @@ void Logger::setLogPriority(Priority logPriority)
////////////////////////////////////////////////////////////////////////////////////////////////////
void Logger::setAbortPriority(Priority abortPriority)
{
m_abortPriority = abortPriority;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Logger::setColorPolicy(ColorStream::ColorPolicy colorPolicy)
{
m_outputStream.setColorPolicy(colorPolicy);
@ -137,8 +146,12 @@ void Logger::log(Priority priority, const input::Location &location, const char
{
const auto priorityID = static_cast<int>(priority);
if (priorityID < static_cast<int>(m_logPriority))
// Always show messages that lead to program termination
if (priorityID < static_cast<int>(m_logPriority) &&
priorityID < static_cast<int>(m_abortPriority))
{
return;
}
m_errorStream
<< LocationFormat
@ -148,6 +161,10 @@ void Logger::log(Priority priority, const input::Location &location, const char
<< ResetFormat() << " "
<< MessageBodyFormat << message
<< ResetFormat() << std::endl;
// TODO: print original warning message
if (priorityID >= static_cast<int>(m_abortPriority))
throw std::runtime_error("received warning (treated as error by configuration)");
}
////////////////////////////////////////////////////////////////////////////////////////////////////