Diagnostics: Use command-line option forms in messages

Tweak how we include the diagnostic category name in diagnostic messages
to use the 'command-line option form' (i.e. lower case with hyphens)
rather than the 'identifier form' (upper case with underscores). This
looks nicer, as it avoids unnecessary 'shouting'.
This commit is contained in:
Matthew Woehlke
2026-03-20 14:20:23 -04:00
parent 436bfb628c
commit 0b65420670
+10 -4
View File
@@ -2,11 +2,10 @@
file LICENSE.rst or https://cmake.org/licensing for details. */
#include "cmMessenger.h"
#include <algorithm>
#include <sstream>
#include <utility>
#include <cm/string_view>
#include "cmDocumentationFormatter.h"
#include "cmMessageMetadata.h"
#include "cmMessageType.h"
@@ -49,6 +48,14 @@ char const* getMessageTypeStr(MessageType t)
return "Warning";
}
std::string getDiagnosticCategoryStr(cmDiagnosticCategory category)
{
std::string out = cmSystemTools::LowerCase(
cmDiagnostics::GetCategoryString(category).substr(4));
std::replace(out.begin(), out.end(), '_', '-');
return out;
}
cm::StdIo::TermAttr getMessageColor(MessageType t)
{
switch (t) {
@@ -250,8 +257,7 @@ void cmMessenger::DisplayMessage(MessageType type,
// Print the message preamble.
msg << "CMake " << getMessageTypeStr(type);
if (category != cmDiagnostics::CMD_NONE) {
cm::string_view const cname = cmDiagnostics::GetCategoryString(category);
msg << " (" << cname.substr(4) << ')';
msg << " (" << getDiagnosticCategoryStr(category) << ')';
}
// Add the immediate context.