From 6d0b8c31c4e0b5d5b60852ca626e170a29734456 Mon Sep 17 00:00:00 2001 From: AdmiringWorm Date: Thu, 8 Feb 2024 17:26:37 +0100 Subject: [PATCH] (#439) Add option to disable warning to stderr This updates the handling of how we output log messages to the console to instead of blindly outputting warning messages to stderr all the time, it will instead check if an environment variable called `CI` is available and set to true, or the user themself have specified the `--ci` argument. When CI system is detected, any warnings will instead be outputted to the normal stdout along with normal informational messages. --- .../Logging/LogConfiguration.cs | 2 +- .../Options/BaseSubOptions.cs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/GitReleaseManager.Cli/Logging/LogConfiguration.cs b/src/GitReleaseManager.Cli/Logging/LogConfiguration.cs index b03f0e57..1799709f 100644 --- a/src/GitReleaseManager.Cli/Logging/LogConfiguration.cs +++ b/src/GitReleaseManager.Cli/Logging/LogConfiguration.cs @@ -43,7 +43,7 @@ private static void CreateConsoleFullLogger(LoggerConfiguration config, string c .Filter.ByExcluding((logEvent) => !options.Verbose && logEvent.Level == LogEventLevel.Verbose) .WriteTo.Console( outputTemplate: consoleTemplate, - standardErrorFromLevel: LogEventLevel.Warning, + standardErrorFromLevel: options.IsCISystem ? LogEventLevel.Error : LogEventLevel.Warning, theme: consoleTheme)); } diff --git a/src/GitReleaseManager.Core/Options/BaseSubOptions.cs b/src/GitReleaseManager.Core/Options/BaseSubOptions.cs index c8a15ad1..9d8b1251 100644 --- a/src/GitReleaseManager.Core/Options/BaseSubOptions.cs +++ b/src/GitReleaseManager.Core/Options/BaseSubOptions.cs @@ -1,9 +1,21 @@ +using System; using CommandLine; namespace GitReleaseManager.Core.Options { public abstract class BaseSubOptions { + protected BaseSubOptions() + { + var ciEnvironmentVariable = Environment.GetEnvironmentVariable("CI"); + + bool isCiSystem; + if (!string.IsNullOrEmpty(ciEnvironmentVariable) && bool.TryParse(ciEnvironmentVariable, out isCiSystem)) + { + IsCISystem = isCiSystem; + } + } + [Option("debug", HelpText = "Enable debugging console output")] public bool Debug { get; set; } @@ -18,5 +30,8 @@ public abstract class BaseSubOptions [Option("verbose", HelpText = "Enable verbose console output")] public bool Verbose { get; set; } + + [Option("ci", HelpText = "Configure GitReleaseManager to be compatible with CI systems")] + public bool IsCISystem { get; set; } } } \ No newline at end of file