Skip to content

Commit a8286e1

Browse files
authored
Merge pull request #4054 from FrankRay78/2470-Call-multiple-tasks-from-CLI-and-pass-them-to-RunTarget
GH2470: call multiple tasks from cli and pass them to run target
2 parents c5036cc + 1b5b6c8 commit a8286e1

13 files changed

Lines changed: 758 additions & 41 deletions

File tree

src/Cake.Cli/Hosts/BuildScriptHost.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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.Collections.Generic;
56
using System.Threading.Tasks;
67
using Cake.Core;
78
using Cake.Core.Diagnostics;
@@ -70,7 +71,21 @@ public override async Task<CakeReport> RunTargetAsync(string target)
7071
{
7172
Settings.SetTarget(target);
7273

74+
return await internalRunTargetAsync();
75+
}
76+
77+
/// <inheritdoc/>
78+
public override async Task<CakeReport> RunTargetsAsync(IEnumerable<string> targets)
79+
{
80+
Settings.SetTargets(targets);
81+
82+
return await internalRunTargetAsync();
83+
}
84+
85+
private async Task<CakeReport> internalRunTargetAsync()
86+
{
7387
var report = await Engine.RunTargetAsync(_context, _executionStrategy, Settings).ConfigureAwait(false);
88+
7489
if (report != null && !report.IsEmpty)
7590
{
7691
_reportPrinter.Write(report);

src/Cake.Cli/Hosts/DescriptionScriptHost.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ public DescriptionScriptHost(ICakeEngine engine, ICakeContext context, IConsole
3333

3434
/// <inheritdoc/>
3535
public override Task<CakeReport> RunTargetAsync(string target)
36+
{
37+
PrintTaskDescriptions();
38+
39+
return System.Threading.Tasks.Task.FromResult<CakeReport>(null);
40+
}
41+
42+
/// <inheritdoc/>
43+
public override Task<CakeReport> RunTargetsAsync(IEnumerable<string> targets)
44+
{
45+
PrintTaskDescriptions();
46+
47+
return System.Threading.Tasks.Task.FromResult<CakeReport>(null);
48+
}
49+
50+
private void PrintTaskDescriptions()
3651
{
3752
var maxTaskNameLength = 29;
3853

@@ -56,8 +71,6 @@ public override Task<CakeReport> RunTargetAsync(string target)
5671
{
5772
_console.WriteLine(lineFormat, key, _descriptions[key]);
5873
}
59-
60-
return System.Threading.Tasks.Task.FromResult<CakeReport>(null);
6174
}
62-
}
75+
}
6376
}

src/Cake.Cli/Hosts/DryRunScriptHost.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Collections.Generic;
67
using System.Threading.Tasks;
78
using Cake.Core;
89
using Cake.Core.Diagnostics;
@@ -66,5 +67,24 @@ public override async Task<CakeReport> RunTargetAsync(string target)
6667

6768
return result;
6869
}
70+
71+
/// <inheritdoc/>
72+
public override async Task<CakeReport> RunTargetsAsync(IEnumerable<string> targets)
73+
{
74+
_log.Information("Performing dry run...");
75+
_log.Information("Targets are: {0}", string.Join(", ", targets));
76+
_log.Information(string.Empty);
77+
78+
Settings.SetTargets(targets);
79+
80+
var strategy = new DryRunExecutionStrategy(_log);
81+
var result = await Engine.RunTargetAsync(Context, strategy, Settings).ConfigureAwait(false);
82+
83+
_log.Information(string.Empty);
84+
_log.Information("This was a dry run.");
85+
_log.Information("No tasks were actually executed.");
86+
87+
return result;
88+
}
6989
}
7090
}

src/Cake.Cli/Hosts/TreeScriptHost.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ public TreeScriptHost(ICakeEngine engine, ICakeContext context, IConsole console
3737

3838
/// <inheritdoc/>
3939
public override Task<CakeReport> RunTargetAsync(string target)
40+
{
41+
PrintTaskTree();
42+
43+
return System.Threading.Tasks.Task.FromResult<CakeReport>(null);
44+
}
45+
46+
/// <inheritdoc/>
47+
public override Task<CakeReport> RunTargetsAsync(IEnumerable<string> targets)
48+
{
49+
PrintTaskTree();
50+
51+
return System.Threading.Tasks.Task.FromResult<CakeReport>(null);
52+
}
53+
54+
private void PrintTaskTree()
4055
{
4156
var topLevelTasks = GetTopLevelTasks();
4257
_console.WriteLine();
@@ -46,8 +61,6 @@ public override Task<CakeReport> RunTargetAsync(string target)
4661
PrintTask(task, string.Empty, false, 0);
4762
_console.WriteLine();
4863
}
49-
50-
return System.Threading.Tasks.Task.FromResult<CakeReport>(null);
5164
}
5265

5366
private List<ICakeTaskInfo> GetTopLevelTasks()

src/Cake.Core.Tests/Fixtures/ScriptHostFixture.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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.Collections.Generic;
56
using System.Threading.Tasks;
67
using Cake.Core.Diagnostics;
78
using Cake.Core.IO;
@@ -23,6 +24,12 @@ public override Task<CakeReport> RunTargetAsync(string target)
2324
{
2425
return System.Threading.Tasks.Task.FromResult(new CakeReport());
2526
}
27+
28+
/// <inheritdoc/>
29+
public override Task<CakeReport> RunTargetsAsync(IEnumerable<string> targets)
30+
{
31+
return System.Threading.Tasks.Task.FromResult(new CakeReport());
32+
}
2633
}
2734

2835
public ICakeEngine Engine { get; set; }

0 commit comments

Comments
 (0)