-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
75 lines (65 loc) · 2.22 KB
/
Program.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using DemoGit.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace DemoGit;
internal class Program(DemoGit demoGit)
{
private readonly DemoGit _demogit = demoGit;
static async Task Main(string[] args)
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
services.AddSingleton<DemoGit>();
services.AddSingleton<Program>();
services.AddTransient<DemoGitCommands>();
})
.Build();
var program = host.Services.GetRequiredService<Program>();
await program.RunAsync();
}
public async Task RunAsync()
{
try
{
while(true)
{
var path = Directory.GetCurrentDirectory();
SystemCommandHandler.PrintPrompt(path);
var input = Console.ReadLine();
if(string.IsNullOrWhiteSpace(input))
{
Console.WriteLine("Error: Input cannot be empty or whitespace.");
continue;
}
var (command, arguments) = SystemCommandHandler.ParseInput(input);
if(command == "demogit")
{
try
{
await _demogit.HandleDemoGitCommandAsync(arguments);
}
catch(Exception ex)
{
Console.WriteLine($"Error in DemoGit command: {ex.Message}");
}
}
else
{
try
{
SystemCommandHandler.RunSystemCommand(command, arguments);
}
catch(Exception ex)
{
Console.WriteLine($"Error running system command '{command}': {ex.Message}");
}
}
}
}
catch(Exception ex)
{
Console.WriteLine($"Critical error: {ex.Message}. The application will terminate.");
}
}
}