/
DebugCommand.cs
53 lines (44 loc) · 1.61 KB
/
DebugCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Licensed to the .NET Foundation under one or more agreements.
// 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.Threading;
using Cake.Core.Diagnostics;
using Cake.Core.Scripting;
using Cake.Diagnostics;
using Cake.Scripting;
namespace Cake.Commands
{
/// <summary>
/// A command that builds and debugs a build script.
/// </summary>
internal sealed class DebugCommand : ICommand
{
private readonly IScriptRunner _scriptRunner;
private readonly IDebugger _debugger;
private readonly ICakeLog _log;
private readonly BuildScriptHost _host;
// Delegate factory used by Autofac.
public delegate DebugCommand Factory();
public DebugCommand(IScriptRunner scriptRunner, IDebugger debugger, BuildScriptHost host)
{
_scriptRunner = scriptRunner;
_debugger = debugger;
_host = host;
_log = _host.Context.Log;
}
public bool Execute(CakeOptions options)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
_log.Debug("Performing debug...");
_log.Information(Verbosity.Quiet, "Attach debugger to process {0} to continue", _debugger.GetProcessId());
_debugger.WaitForAttach(Timeout.InfiniteTimeSpan);
_log.Debug("Debugger attached");
_scriptRunner.Run(_host, options.Script, options.Arguments);
return true;
}
}
}