-
Notifications
You must be signed in to change notification settings - Fork 14
/
Program.cs
151 lines (130 loc) · 6.37 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using CQRSAndMediator.Scaffolding.Builders;
using CQRSAndMediator.Scaffolding.Enums;
using CQRSAndMediator.Scaffolding.Infrastructure;
using CQRSAndMediator.Scaffolding.Resolver;
using McMaster.Extensions.CommandLineUtils;
using System;
using System.IO;
using CQRSAndMediator.Scaffolding.Utilities;
namespace CQRSAndMediator.Scaffolding
{
class Program
{
public static int Main(string[] args)
{
return RunScaffolding(args);
}
private static int RunScaffolding(string[] args)
{
var app = new CommandLineApplication
{
Name = "Scaffolding CLI",
Description = "A CQRS and Mediator scaffolding CLI",
AllowArgumentSeparator = true,
};
app.HelpOption(true);
//Top level command which can split into two directions
app.Command("new", configCmd =>
{
configCmd.OnExecute(() =>
{
Console.WriteLine("Scaffold a new solution or extend the domain");
configCmd.ShowHelp();
return 1;
});
//Split 1: sln
configCmd.Command("sln", setCmd =>
{
setCmd.Description =
"Scaffold a new solution including the API, Logic, DB, Unit and Integration test projects";
var nameArgument = setCmd.Option("-n| --name <NAME>","Name of the solution", CommandOptionType.SingleValue).IsRequired();
setCmd.OnExecute(() =>
{
var path = Directory.GetCurrentDirectory();
BuilderSolution.Build(nameArgument.Value());
BuildStartup.Build($"{path}/API");
BuildCorsExtension.Build($"{path}/API/Extensions");
BuildHealthCheckExtensions.Build($"{path}/API/Extensions");
BuildDatabaseServiceCollectionExtensions.Build($"{path}/DB/Configuration");
BuildLogicServiceCollectionExtensions.Build($"{path}/Logic/Configuration");
Console.WriteLine(ExecuteCommandUtility.Run($"echo [92mDONE[0m"));
});
});
//Split 2: domain
configCmd.Command("domain", setCmd =>
{
setCmd.Description = "Extent the domain with new handlers";
var operationType = setCmd.Option(
"-ot|--operationType <TYPE>",
"Can either be [command] or [query]",
CommandOptionType.SingleValue)
.IsRequired(false,
"Must specify an operation type: Can either be [command] or [query] i.e -ot|--operationType <TYPE>");
var concern = setCmd.Option(
"-c|--concern <NAME>",
"Name of the concern",
CommandOptionType.SingleValue)
.IsRequired(false, "Name of the concern: -c|--concern <NAME>");
var operation = setCmd.Option(
"-o|--operation <NAME>",
"Name of the operation",
CommandOptionType.SingleValue)
.IsRequired(false, "Name of the operation: -o|--operation <NAME>");
var groupBy = setCmd.Option(
"-g|--groupBy <TYPE>",
"Group domain objects by [C] for concerns or [O] for operations, defaults to concerns",
CommandOptionType.SingleValue);
setCmd.OnExecute(() =>
{
var groupByType = GroupByType.Concern;
if (groupBy.HasValue())
{
groupByType = (groupBy.Value()?.ToLower()) switch
{
"c" => GroupByType.Concern,
"o" => GroupByType.Operation,
_ => GroupByType.Concern
};
}
var operationTypeBuilderResult = OperationTypeResolver.Resolve(operationType.Value());
if (operationTypeBuilderResult == OperationType.UNSUPPORTED)
{
LogUtility.Error("Invalid operation type parameter: must specify [c] for command or [q] for query");
return 0;
}
BuildResponse.Build(concern.Value(), operation.Value(), groupByType);
switch (operationTypeBuilderResult)
{
case OperationType.COMMAND:
BuildCommand.Build(concern.Value(), operation.Value(), groupByType);
break;
case OperationType.QUERY:
BuildQuery.Build(concern.Value(), operation.Value(), groupByType);
break;
case OperationType.UNSUPPORTED:
LogUtility.Error(
"Invalid operation type parameter: must specify [c] for command or [q] for query");
break;
default:
LogUtility.Error(
"Invalid operation type parameter: must specify [c] for command or [q] for query");
break;
};
BuildHandler.Build(concern.Value(), operation.Value(), operationTypeBuilderResult, groupByType);
return 0;
});
});
});
//Split 3 : Message bus
//TODO: Add scaffolding to create messagebus consumer or producer
//Split 3 : Redis cache
//TODO: Add scaffolding to create either a cached api route or cached resource
app.OnExecute(() =>
{
app.ShowHelp();
return 1;
});
return app.Execute(args);
}
}
}