Added command-line option to control color output.

This commit is contained in:
Patrick Lühne 2016-11-24 15:01:37 +01:00
parent f6e6b6fd60
commit c12da5d44a
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
1 changed files with 18 additions and 1 deletions

View File

@ -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"))