Implemented new command-line options replacing --warning-level.
This commit is contained in:
parent
cfce6b1bbd
commit
9e1cdaaa51
@ -6,6 +6,8 @@ Features:
|
|||||||
|
|
||||||
* extended PDDL support (`imply` expressions)
|
* extended PDDL support (`imply` expressions)
|
||||||
* improved command-line interface
|
* 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)
|
## 3.0.3 (2016-09-02)
|
||||||
|
|
||||||
|
40
app/main.cpp
40
app/main.cpp
@ -16,14 +16,17 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
|
bool warningsAsErrors;
|
||||||
|
|
||||||
po::options_description description("Allowed options");
|
po::options_description description("Allowed options");
|
||||||
description.add_options()
|
description.add_options()
|
||||||
("help,h", "Display this help message")
|
("help,h", "Display this help message")
|
||||||
("version,v", "Display version information")
|
("version,v", "Display version information")
|
||||||
("input,i", po::value<std::vector<std::string>>(), "Input files (in PDDL or SAS format)")
|
("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)")
|
("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;
|
po::positional_options_description positionalOptionsDescription;
|
||||||
positionalOptionsDescription.add("input", -1);
|
positionalOptionsDescription.add("input", -1);
|
||||||
@ -70,22 +73,8 @@ int main(int argc, char **argv)
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto warningLevel = variablesMap["warning-level"].as<std::string>();
|
if (warningsAsErrors)
|
||||||
|
logger.setAbortPriority(plasp::output::Priority::Warning);
|
||||||
// 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;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
const auto colorPolicy = variablesMap["color"].as<std::string>();
|
const auto colorPolicy = variablesMap["color"].as<std::string>();
|
||||||
|
|
||||||
@ -103,6 +92,21 @@ int main(int argc, char **argv)
|
|||||||
return EXIT_FAILURE;
|
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
|
try
|
||||||
{
|
{
|
||||||
plasp::input::Parser<plasp::input::CaseInsensitiveParserPolicy> parser;
|
plasp::input::Parser<plasp::input::CaseInsensitiveParserPolicy> parser;
|
||||||
|
@ -30,8 +30,10 @@ class Logger
|
|||||||
ColorStream &outputStream();
|
ColorStream &outputStream();
|
||||||
ColorStream &errorStream();
|
ColorStream &errorStream();
|
||||||
|
|
||||||
// The level from which on messages should be printed
|
// The priority from which on messages should be printed
|
||||||
void setLogPriority(Priority logPriority);
|
void setLogPriority(Priority logPriority);
|
||||||
|
// Messages with this priority (or higher) will terminate the program’s execution
|
||||||
|
void setAbortPriority(Priority abortPriority);
|
||||||
void setColorPolicy(ColorStream::ColorPolicy colorPolicy);
|
void setColorPolicy(ColorStream::ColorPolicy colorPolicy);
|
||||||
|
|
||||||
void log(Priority priority, const char *message);
|
void log(Priority priority, const char *message);
|
||||||
@ -44,6 +46,7 @@ class Logger
|
|||||||
ColorStream m_errorStream;
|
ColorStream m_errorStream;
|
||||||
|
|
||||||
Priority m_logPriority;
|
Priority m_logPriority;
|
||||||
|
Priority m_abortPriority;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -57,7 +57,8 @@ Logger::Logger(ColorStream &&outputStream)
|
|||||||
Logger::Logger(ColorStream &&outputStream, ColorStream &&errorStream)
|
Logger::Logger(ColorStream &&outputStream, ColorStream &&errorStream)
|
||||||
: m_outputStream{outputStream},
|
: m_outputStream{outputStream},
|
||||||
m_errorStream{errorStream},
|
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)
|
Logger::Logger(Logger &&other)
|
||||||
: m_outputStream{std::move(other.m_outputStream)},
|
: m_outputStream{std::move(other.m_outputStream)},
|
||||||
m_errorStream{std::move(other.m_errorStream)},
|
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)
|
void Logger::setColorPolicy(ColorStream::ColorPolicy colorPolicy)
|
||||||
{
|
{
|
||||||
m_outputStream.setColorPolicy(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);
|
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;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_errorStream
|
m_errorStream
|
||||||
<< LocationFormat
|
<< LocationFormat
|
||||||
@ -148,6 +161,10 @@ void Logger::log(Priority priority, const input::Location &location, const char
|
|||||||
<< ResetFormat() << " "
|
<< ResetFormat() << " "
|
||||||
<< MessageBodyFormat << message
|
<< MessageBodyFormat << message
|
||||||
<< ResetFormat() << std::endl;
|
<< 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)");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Reference in New Issue
Block a user