using System.Text.Json; namespace FinalFactory.Rendezvous.Capacity; internal static class Program { private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web) { WriteIndented = true, }; public static async Task Main(string[] args) { CapacityOptions options; try { options = CapacityOptions.Parse(args); } catch (ArgumentException exception) { Console.Error.WriteLine(exception.Message); return 2; } CapacityReport report = await CapacityRunner.RunAsync(options).ConfigureAwait(false); string json = JsonSerializer.Serialize(report, JsonOptions); Console.WriteLine(json); if (options.OutputPath is not null) { string fullPath = Path.GetFullPath(options.OutputPath); Directory.CreateDirectory(Path.GetDirectoryName(fullPath)!); await File.WriteAllTextAsync(fullPath, json + Environment.NewLine).ConfigureAwait(false); } return report.Passed ? 0 : 1; } }