Skip to content

Commit ca440e5

Browse files
committed
(#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.
1 parent f20ad25 commit ca440e5

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/Cake.Cli/Hosts/BuildScriptHost.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System;
56
using System.Collections.Generic;
67
using System.Threading.Tasks;
78
using Cake.Core;
9+
using Cake.Core.Configuration;
810
using Cake.Core.Diagnostics;
911
using Cake.Core.Scripting;
1012

@@ -22,13 +24,15 @@ public sealed class BuildScriptHost : BuildScriptHost<ICakeContext>
2224
/// <param name="executionStrategy">The execution strategy.</param>
2325
/// <param name="context">The context.</param>
2426
/// <param name="reportPrinter">The report printer.</param>
27+
/// <param name="configuration">The Cake Configuration.</param>
2528
/// <param name="log">The log.</param>
2629
public BuildScriptHost(
2730
ICakeEngine engine,
2831
IExecutionStrategy executionStrategy,
2932
ICakeContext context,
3033
ICakeReportPrinter reportPrinter,
31-
ICakeLog log) : base(engine, executionStrategy, context, reportPrinter, log)
34+
ICakeConfiguration configuration,
35+
ICakeLog log) : base(engine, executionStrategy, context, reportPrinter, configuration, log)
3236
{
3337
}
3438
}
@@ -44,6 +48,7 @@ public class BuildScriptHost<TContext> : ScriptHost
4448
private readonly ICakeLog _log;
4549
private readonly IExecutionStrategy _executionStrategy;
4650
private readonly TContext _context;
51+
private readonly ICakeConfiguration _configuration;
4752

4853
/// <summary>
4954
/// Initializes a new instance of the <see cref="BuildScriptHost{TContext}"/> class.
@@ -52,17 +57,20 @@ public class BuildScriptHost<TContext> : ScriptHost
5257
/// <param name="executionStrategy">The execution strategy.</param>
5358
/// <param name="context">The context.</param>
5459
/// <param name="reportPrinter">The report printer.</param>
60+
/// <param name="configuration">The Cake Configuration.</param>
5561
/// <param name="log">The log.</param>
5662
public BuildScriptHost(
5763
ICakeEngine engine,
5864
IExecutionStrategy executionStrategy,
5965
TContext context,
6066
ICakeReportPrinter reportPrinter,
67+
ICakeConfiguration configuration,
6168
ICakeLog log) : base(engine, context)
6269
{
6370
_executionStrategy = executionStrategy;
6471
_context = context;
6572
_reportPrinter = reportPrinter;
73+
_configuration = configuration;
6674
_log = log;
6775
}
6876

@@ -88,7 +96,8 @@ private async Task<CakeReport> internalRunTargetAsync()
8896
{
8997
var report = await Engine.RunTargetAsync(_context, _executionStrategy, Settings).ConfigureAwait(false);
9098

91-
if (report != null && !report.IsEmpty)
99+
var noReportEnabled = _configuration.GetValue("Settings_NoReport") ?? bool.FalseString;
100+
if (report != null && !report.IsEmpty && !noReportEnabled.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase))
92101
{
93102
_reportPrinter.Write(report);
94103
}

src/Cake/Commands/DefaultCommandSettings.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,12 @@ public sealed class DefaultCommandSettings : CommandSettings
102102
[CommandOption("--" + Infrastructure.Constants.Cache.InvalidateScriptCache)]
103103
[Description("Forces the script to be recompiled if caching is enabled.")]
104104
public bool Recompile { get; set; }
105+
106+
/// <summary>
107+
/// Gets or sets a value indicating whether to display report summary at the end of Cake execution.
108+
/// </summary>
109+
[CommandOption("--" + Infrastructure.Constants.CakeExecution.NoReport)]
110+
[Description("Prevent the display of the summary report at the end of Cake Execution.")]
111+
public bool NoReport { get; set; }
105112
}
106113
}

src/Cake/Infrastructure/Constants.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public static class Settings
1010
{
1111
public const string EnableScriptCache = "Settings_EnableScriptCache";
1212
public const string UseSpectreConsoleForConsoleOutput = "Settings_UseSpectreConsoleForConsoleOutput";
13+
public const string NoReport = "Settings_NoReport";
1314
}
1415

1516
public static class Paths
@@ -21,5 +22,10 @@ public static class Cache
2122
{
2223
public const string InvalidateScriptCache = "invalidate-script-cache";
2324
}
25+
26+
public static class CakeExecution
27+
{
28+
public const string NoReport = "no-report";
29+
}
2430
}
2531
}

0 commit comments

Comments
 (0)