-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
111 lines (92 loc) · 3.86 KB
/
Program.cs
File metadata and controls
111 lines (92 loc) · 3.86 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using CodeTower.Interfaces;
using CodeTower.Models;
using CodeTower.Services;
using Microsoft.Extensions.DependencyInjection;
using System.CommandLine;
namespace CodeTower;
public class Program
{
private static async Task Main(string[] args)
{
var services = ConfigureServices();
var rootCommand = new RootCommand("CodeTower Architecture Restructuring Tool");
ConfigureCommands(rootCommand, services);
await rootCommand.InvokeAsync(args);
}
private static IServiceProvider ConfigureServices()
{
var services = new ServiceCollection();
// Register services
services.AddSingleton<ILogger, ConsoleLogger>();
services.AddSingleton<IBackupService, BackupService>();
services.AddSingleton<IDependencyAnalyzer, DependencyAnalyzer>();
services.AddSingleton<IRestructuringEngine, RestructuringEngine>();
services.AddSingleton<IScaffoldingGenerator, ScaffoldingGenerator>();
return services.BuildServiceProvider();
}
private static void ConfigureCommands(RootCommand rootCommand, IServiceProvider services)
{
var solutionOption = new Option<FileInfo>("--solution", "Path to solution file") { IsRequired = true };
var configOption = new Option<FileInfo>("--config", "Path to restructuring config file");
var restructureCommand = new Command("restructure", "Perform solution restructuring");
restructureCommand.AddOption(solutionOption);
restructureCommand.AddOption(configOption);
var generateCommand = new Command("generate", "Generate scaffolding for architecture");
generateCommand.AddOption(solutionOption);
generateCommand.AddOption(new Option<string>("--template", "Architecture template name"));
rootCommand.AddCommand(restructureCommand);
rootCommand.AddCommand(generateCommand);
restructureCommand.SetHandler(async (solution, config) =>
{
await HandleRestructureCommand(services, solution, config);
}, solutionOption, configOption);
generateCommand.SetHandler(async (solution, template) =>
{
await HandleGenerateCommand(services, solution, template);
}, solutionOption, new Option<string>("--template"));
}
private static async Task HandleRestructureCommand(
IServiceProvider services,
FileInfo solutionFile,
FileInfo configFile)
{
var logger = services.GetRequiredService<ILogger>();
var engine = services.GetRequiredService<IRestructuringEngine>();
try
{
var config = await RestructuringConfig.LoadAsync(configFile);
await engine.InitializeAsync(solutionFile.FullName);
foreach (var transformation in config.Transformations)
{
await engine.ApplyTransformationAsync(transformation);
}
await engine.CommitChangesAsync();
logger.LogInformation("Restructuring completed successfully");
}
catch (Exception ex)
{
logger.LogError("Restructuring failed", ex);
Environment.Exit(1);
}
}
private static async Task HandleGenerateCommand(
IServiceProvider services,
FileInfo solutionFile,
string templateName)
{
var logger = services.GetRequiredService<ILogger>();
var generator = services.GetRequiredService<IScaffoldingGenerator>();
try
{
await generator.InitializeAsync(solutionFile.FullName);
await generator.GenerateArchitectureAsync(templateName);
await generator.CommitChangesAsync();
logger.LogInformation("Scaffolding generated successfully");
}
catch (Exception ex)
{
logger.LogError("Scaffolding generation failed", ex);
Environment.Exit(1);
}
}
}