forked from dotnetcore/FlubuCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
74 lines (62 loc) · 2.32 KB
/
Copy pathProgram.cs
File metadata and controls
74 lines (62 loc) · 2.32 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.IO;
using System.Threading;
using DotNet.Cli.Flubu.Commanding;
using DotNet.Cli.Flubu.Infrastructure;
using FlubuCore.Commanding;
using FlubuCore.Context;
using FlubuCore.Infrastructure;
using McMaster.Extensions.CommandLineUtils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace DotNet.Cli.Flubu
{
public static class Program
{
private static readonly IServiceCollection Services = new ServiceCollection();
private static IServiceProvider _provider;
private static bool _cleanUpPerformed = false;
private static volatile bool _wait = false;
public static int Main(string[] args)
{
if (args == null)
{
args = new string[0];
}
Services
.AddCoreComponents()
.AddCommandComponents()
.AddScriptAnalyser()
.AddArguments(args)
.AddTasks();
_provider = Services.BuildServiceProvider();
ILoggerFactory factory = _provider.GetRequiredService<ILoggerFactory>();
factory.AddProvider(new FlubuLoggerProvider());
var cmdApp = _provider.GetRequiredService<CommandLineApplication>();
ICommandExecutor executor = _provider.GetRequiredService<ICommandExecutor>();
executor.FlubuHelpText = cmdApp.GetHelpText();
Console.CancelKeyPress += OnCancelKeyPress;
var result = executor.ExecuteAsync().Result;
while (_wait)
{
Thread.Sleep(250);
}
return result;
}
private static void OnCancelKeyPress(object sender, ConsoleCancelEventArgs eventArgs)
{
if (!_cleanUpPerformed && CleanUpStore.TaskCleanUpActions?.Count > 0)
{
_wait = true;
Console.WriteLine($"Performing clean up actions:");
var taskSession = _provider.GetService<IFlubuSession>();
foreach (var cleanUpAction in CleanUpStore.TaskCleanUpActions)
{
cleanUpAction.Invoke(taskSession);
Console.WriteLine($"Finished performing clean up actions.");
}
_wait = false;
}
}
}
}