From ca440e570e3bdc8dec69d4ce336618d3f418ea0a Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Sat, 6 Dec 2025 16:42:40 +0000 Subject: [PATCH] (#2101) Allow report summary to not be shown As part of a normal Cake execution, a report summary is always shown at the end. This includes information about what tasks were ran, how long they took, etc. However, there are those that don't want to allow this to happen. This commit introduces a new configuration option, which allows the report summary to not be shown. This can be done in the usual way with a command line parameter, cake.config file entry, or an environment variable. --- src/Cake.Cli/Hosts/BuildScriptHost.cs | 13 +++++++++++-- src/Cake/Commands/DefaultCommandSettings.cs | 7 +++++++ src/Cake/Infrastructure/Constants.cs | 6 ++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Cake.Cli/Hosts/BuildScriptHost.cs b/src/Cake.Cli/Hosts/BuildScriptHost.cs index 7dd7ee1bc9..a12f5725bd 100644 --- a/src/Cake.Cli/Hosts/BuildScriptHost.cs +++ b/src/Cake.Cli/Hosts/BuildScriptHost.cs @@ -2,9 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.Collections.Generic; using System.Threading.Tasks; using Cake.Core; +using Cake.Core.Configuration; using Cake.Core.Diagnostics; using Cake.Core.Scripting; @@ -22,13 +24,15 @@ public sealed class BuildScriptHost : BuildScriptHost /// The execution strategy. /// The context. /// The report printer. + /// The Cake Configuration. /// The log. public BuildScriptHost( ICakeEngine engine, IExecutionStrategy executionStrategy, ICakeContext context, ICakeReportPrinter reportPrinter, - ICakeLog log) : base(engine, executionStrategy, context, reportPrinter, log) + ICakeConfiguration configuration, + ICakeLog log) : base(engine, executionStrategy, context, reportPrinter, configuration, log) { } } @@ -44,6 +48,7 @@ public class BuildScriptHost : ScriptHost private readonly ICakeLog _log; private readonly IExecutionStrategy _executionStrategy; private readonly TContext _context; + private readonly ICakeConfiguration _configuration; /// /// Initializes a new instance of the class. @@ -52,17 +57,20 @@ public class BuildScriptHost : ScriptHost /// The execution strategy. /// The context. /// The report printer. + /// The Cake Configuration. /// The log. public BuildScriptHost( ICakeEngine engine, IExecutionStrategy executionStrategy, TContext context, ICakeReportPrinter reportPrinter, + ICakeConfiguration configuration, ICakeLog log) : base(engine, context) { _executionStrategy = executionStrategy; _context = context; _reportPrinter = reportPrinter; + _configuration = configuration; _log = log; } @@ -88,7 +96,8 @@ private async Task internalRunTargetAsync() { var report = await Engine.RunTargetAsync(_context, _executionStrategy, Settings).ConfigureAwait(false); - if (report != null && !report.IsEmpty) + var noReportEnabled = _configuration.GetValue("Settings_NoReport") ?? bool.FalseString; + if (report != null && !report.IsEmpty && !noReportEnabled.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase)) { _reportPrinter.Write(report); } diff --git a/src/Cake/Commands/DefaultCommandSettings.cs b/src/Cake/Commands/DefaultCommandSettings.cs index c2a12e2628..cdc111d48e 100644 --- a/src/Cake/Commands/DefaultCommandSettings.cs +++ b/src/Cake/Commands/DefaultCommandSettings.cs @@ -102,5 +102,12 @@ public sealed class DefaultCommandSettings : CommandSettings [CommandOption("--" + Infrastructure.Constants.Cache.InvalidateScriptCache)] [Description("Forces the script to be recompiled if caching is enabled.")] public bool Recompile { get; set; } + + /// + /// Gets or sets a value indicating whether to display report summary at the end of Cake execution. + /// + [CommandOption("--" + Infrastructure.Constants.CakeExecution.NoReport)] + [Description("Prevent the display of the summary report at the end of Cake Execution.")] + public bool NoReport { get; set; } } } diff --git a/src/Cake/Infrastructure/Constants.cs b/src/Cake/Infrastructure/Constants.cs index 7268826672..0741ac247d 100644 --- a/src/Cake/Infrastructure/Constants.cs +++ b/src/Cake/Infrastructure/Constants.cs @@ -10,6 +10,7 @@ public static class Settings { public const string EnableScriptCache = "Settings_EnableScriptCache"; public const string UseSpectreConsoleForConsoleOutput = "Settings_UseSpectreConsoleForConsoleOutput"; + public const string NoReport = "Settings_NoReport"; } public static class Paths @@ -21,5 +22,10 @@ public static class Cache { public const string InvalidateScriptCache = "invalidate-script-cache"; } + + public static class CakeExecution + { + public const string NoReport = "no-report"; + } } }