Added command-line option to control color output.
This commit is contained in:
parent
f6e6b6fd60
commit
c12da5d44a
19
app/main.cpp
19
app/main.cpp
@ -15,7 +15,8 @@ int main(int argc, char **argv)
|
||||
description.add_options()
|
||||
("help,h", "Display this help message")
|
||||
("version,v", "Display version information")
|
||||
("input,i", po::value<std::vector<std::string>>(), "Input files");
|
||||
("input,i", po::value<std::vector<std::string>>(), "Input files")
|
||||
("color", po::value<std::string>()->default_value("auto"), "Whether to colorize the output (always, never, or auto).");
|
||||
|
||||
po::positional_options_description positionalOptionsDescription;
|
||||
positionalOptionsDescription.add("input", -1);
|
||||
@ -59,6 +60,22 @@ int main(int argc, char **argv)
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
const auto colorPolicy = variablesMap["color"].as<std::string>();
|
||||
|
||||
if (colorPolicy == "auto")
|
||||
context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Auto);
|
||||
else if (colorPolicy == "never")
|
||||
context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Never);
|
||||
else if (colorPolicy == "always")
|
||||
context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Always);
|
||||
else
|
||||
{
|
||||
context.logger.log(anthem::output::Priority::Error, ("unknown color policy “" + colorPolicy + "”").c_str());
|
||||
context.logger.errorStream() << std::endl;
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (variablesMap.count("input"))
|
||||
|
Loading…
Reference in New Issue
Block a user