fix(buildtool): render --check-prereqs through Spectre like everything else

The flag printed its own Console.WriteLine table while the guided menu rendered
the same PrerequisiteResult list through PrerequisiteChecker. Two renderers for
one result set, free to drift, and only one of them carried the tool's
branding. Call the existing one and delete the duplicate.

Spectre drops ANSI styling on its own when stdout is not a terminal, which is
the case this flag exists for, so redirected output stays clean. It also falls
back to an 80 column width and folds past it, which matters here because the
warnings are shell commands meant to be copied — the CentOS EPEL hint is 95
characters and would have gained a newline mid-command. Widen the profile when
output is redirected.

Exit codes are unchanged: 0 when everything resolves, 1 when anything is
missing.
This commit is contained in:
Kamron Batman 2026-08-07 14:10:49 -07:00
parent 4241f29e2f
commit 5cb1c9e040
No known key found for this signature in database
GPG key ID: 7D81DF26D9A5D94A

View file

@ -4,6 +4,7 @@ using BuildTool.Interactive;
using BuildTool.Platform;
using BuildTool.Prerequisites;
using BuildTool.Publishing;
using Spectre.Console;
Console.OutputEncoding = Encoding.UTF8;
@ -38,25 +39,18 @@ var rid = $"{options.Os}-{options.Arch}";
if (options.CheckPrereqsOnly)
{
var allPassed = true;
foreach (var result in NativeLibraryChecker.Check(detectedPlatform))
// Same renderer the guided menu uses, so the two cannot drift. Spectre drops ANSI styling by
// itself when stdout is not a terminal, which is the case this flag exists for, but it also
// falls back to an 80 column width and folds anything longer. The install hints we print are
// shell commands — the CentOS one is 95 characters — and a fold puts a newline in the middle of
// a command that someone is meant to copy. Widen the profile so they stay on one line.
if (Console.IsOutputRedirected)
{
if (!result.IsWarning)
{
Console.WriteLine($"{result.Name,-16} {(result.Passed ? "OK" : "MISSING"),-8} {result.Details}");
allPassed &= result.Passed;
continue;
}
Console.WriteLine(result.Details);
if (result.InstallCommand is not null)
{
Console.WriteLine($" {result.InstallCommand}");
}
AnsiConsole.Profile.Width = 200;
}
return allPassed ? 0 : 1;
// Exit code is the machine-readable half: 0 when everything resolves, 1 when anything is missing.
return PrerequisiteChecker.CheckNativeLibraries(detectedPlatform, interactive: false) ? 0 : 1;
}
// Run prerequisite checks unless skipped