From cad255122f87305d269afba796680c22bc13b68e Mon Sep 17 00:00:00 2001 From: Christian Helle Date: Tue, 12 Sep 2023 11:33:10 +0200 Subject: [PATCH 1/3] Skip analytics configuration entirely if --no-logging is specified Moved the line that configures Analytics from the Main method of the Program class to the Validate method of the GenerateCommand class. This ensures that analytics will only be configured if the 'NoLogging' setting is not active, optimizing performance and improving the user's control over logging. --- src/Refitter/GenerateCommand.cs | 3 +++ src/Refitter/Program.cs | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Refitter/GenerateCommand.cs b/src/Refitter/GenerateCommand.cs index b1bd4de0..c3afd2ed 100644 --- a/src/Refitter/GenerateCommand.cs +++ b/src/Refitter/GenerateCommand.cs @@ -14,6 +14,9 @@ public sealed class GenerateCommand : AsyncCommand public override ValidationResult Validate(CommandContext context, Settings settings) { + if (!settings.NoLogging) + Analytics.Configure(); + if (string.IsNullOrWhiteSpace(settings.OpenApiPath)) return ValidationResult.Error("Input file is required"); diff --git a/src/Refitter/Program.cs b/src/Refitter/Program.cs index e01e9a1d..f18902d5 100644 --- a/src/Refitter/Program.cs +++ b/src/Refitter/Program.cs @@ -10,8 +10,6 @@ static class Program { static int Main(string[] args) { - Analytics.Configure(); - if (args.Length == 0) { args = new[] From 68775a5ac389d01660f36445fcd4403903b05580 Mon Sep 17 00:00:00 2001 From: Christian Helle Date: Tue, 12 Sep 2023 11:34:06 +0200 Subject: [PATCH 2/3] Skip showing support key if --no-logging is specified In the GenerateCommand.cs, the logging statement showing the support key has been modified. The support key statement is now conditioned to only display when logging is enabled in settings. This was done to provide cleaner outputs when logging is disabled. --- src/Refitter/GenerateCommand.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Refitter/GenerateCommand.cs b/src/Refitter/GenerateCommand.cs index c3afd2ed..5552e303 100644 --- a/src/Refitter/GenerateCommand.cs +++ b/src/Refitter/GenerateCommand.cs @@ -54,12 +54,12 @@ public override async Task ExecuteAsync(CommandContext context, Settings se { var stopwatch = Stopwatch.StartNew(); AnsiConsole.MarkupLine($"[green]Refitter v{GetType().Assembly.GetName().Version!}[/]"); - AnsiConsole.MarkupLine($"[green]Support key: {SupportInformation.GetSupportKey()}[/]"); + + if (!settings.NoLogging) + AnsiConsole.MarkupLine($"[green]Support key: {SupportInformation.GetSupportKey()}[/]"); - if (!settings.SkipValidation) - { + if (!settings.SkipValidation) await ValidateOpenApiSpec(settings); - } if (!string.IsNullOrWhiteSpace(settings.SettingsFilePath)) { From 7a2ef518fb5432415428fd54eb481e9968c07307 Mon Sep 17 00:00:00 2001 From: Christian Helle Date: Tue, 12 Sep 2023 11:39:58 +0200 Subject: [PATCH 3/3] Show message regarding support keys when logging is disabled Adjusted the way the support key is handled when the logging is disabled. Previously, the support key wasn't printed at all if the logging was off. Now, a message specifying that the support key is unavailable when logging is disabled is printed instead. This serves to ensure that users are informed about the unavailability of the support key when logging is off rather than silently omitting it. --- src/Refitter/GenerateCommand.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Refitter/GenerateCommand.cs b/src/Refitter/GenerateCommand.cs index 5552e303..dff5db77 100644 --- a/src/Refitter/GenerateCommand.cs +++ b/src/Refitter/GenerateCommand.cs @@ -54,9 +54,10 @@ public override async Task ExecuteAsync(CommandContext context, Settings se { var stopwatch = Stopwatch.StartNew(); AnsiConsole.MarkupLine($"[green]Refitter v{GetType().Assembly.GetName().Version!}[/]"); - - if (!settings.NoLogging) - AnsiConsole.MarkupLine($"[green]Support key: {SupportInformation.GetSupportKey()}[/]"); + AnsiConsole.MarkupLine( + settings.NoLogging + ? "[green]Support key: Unavailable when logging is disabled[/]" + : $"[green]Support key: {SupportInformation.GetSupportKey()}[/]"); if (!settings.SkipValidation) await ValidateOpenApiSpec(settings); @@ -107,7 +108,7 @@ private static async Task ValidateOpenApiSpec(Settings settings) if (!validationResult.IsValid) { AnsiConsole.MarkupLine($"[red]{Crlf}OpenAPI validation failed:{Crlf}[/]"); - + foreach (var error in validationResult.Diagnostics.Errors) { TryWriteLine(error, "red", "Error"); @@ -117,10 +118,10 @@ private static async Task ValidateOpenApiSpec(Settings settings) { TryWriteLine(warning, "yellow", "Warning"); } - + validationResult.ThrowIfInvalid(); } - + AnsiConsole.MarkupLine($"[green]{Crlf}OpenAPI statistics:{Crlf}{validationResult.Statistics}{Crlf}[/]"); }