up
This commit is contained in:
@@ -593,6 +593,92 @@ internal static class CommandHandlers
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task HandleAdviseBatchAsync(
|
||||
IServiceProvider services,
|
||||
AdvisoryAiTaskType taskType,
|
||||
IReadOnlyList<string> advisoryKeys,
|
||||
string? artifactId,
|
||||
string? artifactPurl,
|
||||
string? policyVersion,
|
||||
string profile,
|
||||
IReadOnlyList<string> preferredSections,
|
||||
bool forceRefresh,
|
||||
int timeoutSeconds,
|
||||
AdvisoryOutputFormat outputFormat,
|
||||
string? outputDirectory,
|
||||
bool verbose,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (advisoryKeys.Count == 0)
|
||||
{
|
||||
throw new ArgumentException("At least one advisory key is required.", nameof(advisoryKeys));
|
||||
}
|
||||
|
||||
var outputDir = string.IsNullOrWhiteSpace(outputDirectory) ? null : Path.GetFullPath(outputDirectory!);
|
||||
if (outputDir is not null)
|
||||
{
|
||||
Directory.CreateDirectory(outputDir);
|
||||
}
|
||||
|
||||
var results = new List<(string Advisory, int ExitCode)>();
|
||||
var overallExit = 0;
|
||||
|
||||
foreach (var key in advisoryKeys)
|
||||
{
|
||||
var sanitized = string.IsNullOrWhiteSpace(key) ? "unknown" : key.Trim();
|
||||
var ext = outputFormat switch
|
||||
{
|
||||
AdvisoryOutputFormat.Json => ".json",
|
||||
AdvisoryOutputFormat.Markdown => ".md",
|
||||
_ => ".txt"
|
||||
};
|
||||
|
||||
var outputPath = outputDir is null ? null : Path.Combine(outputDir, $"{SanitizeFileName(sanitized)}-{taskType.ToString().ToLowerInvariant()}{ext}");
|
||||
|
||||
Environment.ExitCode = 0; // reset per advisory to capture individual result
|
||||
|
||||
await HandleAdviseRunAsync(
|
||||
services,
|
||||
taskType,
|
||||
sanitized,
|
||||
artifactId,
|
||||
artifactPurl,
|
||||
policyVersion,
|
||||
profile,
|
||||
preferredSections,
|
||||
forceRefresh,
|
||||
timeoutSeconds,
|
||||
outputFormat,
|
||||
outputPath,
|
||||
verbose,
|
||||
cancellationToken);
|
||||
|
||||
var code = Environment.ExitCode;
|
||||
results.Add((sanitized, code));
|
||||
overallExit = overallExit == 0 ? code : overallExit; // retain first non-zero if any
|
||||
}
|
||||
|
||||
if (results.Count > 1)
|
||||
{
|
||||
var table = new Table()
|
||||
.Border(TableBorder.Rounded)
|
||||
.Title("[bold]Advisory Batch[/]");
|
||||
table.AddColumn("Advisory");
|
||||
table.AddColumn("Task");
|
||||
table.AddColumn("Exit Code");
|
||||
|
||||
foreach (var result in results)
|
||||
{
|
||||
var exitText = result.ExitCode == 0 ? "[green]0[/]" : $"[red]{result.ExitCode}[/]";
|
||||
table.AddRow(Markup.Escape(result.Advisory), taskType.ToString(), exitText);
|
||||
}
|
||||
|
||||
AnsiConsole.Console.Write(table);
|
||||
}
|
||||
|
||||
Environment.ExitCode = overallExit;
|
||||
}
|
||||
|
||||
public static async Task HandleSourcesIngestAsync(
|
||||
IServiceProvider services,
|
||||
bool dryRun,
|
||||
|
||||
Reference in New Issue
Block a user