-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProgram.cs
122 lines (101 loc) · 4.64 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
// ReSharper disable InvertIf
namespace Atc.Rest.ApiGenerator.CLI;
[ExcludeFromCodeCoverage]
public static class Program
{
public static Task<int> Main(
string[] args)
{
ArgumentNullException.ThrowIfNull(args);
args = SetOutputPathFromDotArgumentIfNeeded(args);
args = SetHelpArgumentIfNeeded(args);
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
.Build();
var consoleLoggerConfiguration = new ConsoleLoggerConfiguration();
configuration.GetRequiredSection("ConsoleLogger").Bind(consoleLoggerConfiguration);
ProgramCsHelper.SetMinimumLogLevelIfNeeded(args, consoleLoggerConfiguration);
var serviceCollection = ServiceCollectionFactory.Create(consoleLoggerConfiguration);
serviceCollection.AddSingleton<ILogItemFactory, LogItemFactory>();
serviceCollection.AddSingleton<IOpenApiDocumentValidator, OpenApiDocumentValidator>();
serviceCollection.AddSingleton<IApiOperationExtractor, ApiOperationExtractor>();
serviceCollection.AddSingleton<INugetPackageReferenceProvider, NugetPackageReferenceProvider>();
serviceCollection.AddSingleton<IAtcApiNugetClient, AtcApiNugetClient>();
serviceCollection.AddSingleton<IAtcCodingRulesUpdater, AtcCodingRulesUpdater>();
var app = CommandAppFactory.CreateWithRootCommand<RootCommand>(serviceCollection);
app.ConfigureCommands();
return app.RunAsync(args);
}
private static string[] SetOutputPathFromDotArgumentIfNeeded(
string[] args)
{
if (!args.Contains(".", StringComparer.Ordinal))
{
return args;
}
var newArgs = new List<string>();
foreach (var s in args)
{
if (".".Equals(s, StringComparison.Ordinal))
{
if (!args.Contains("all", StringComparer.OrdinalIgnoreCase) &&
!args.Contains("host", StringComparer.OrdinalIgnoreCase) &&
!args.Contains("api", StringComparer.OrdinalIgnoreCase) &&
!args.Contains("domain", StringComparer.OrdinalIgnoreCase))
{
newArgs.Add("all");
}
if (newArgs.Contains("all", StringComparer.OrdinalIgnoreCase))
{
if (!args.Contains(ArgumentCommandConstants.LongServerOutputSolutionPath, StringComparer.OrdinalIgnoreCase))
{
newArgs.Add(ArgumentCommandConstants.LongServerOutputSolutionPath);
}
newArgs.Add(Environment.CurrentDirectory);
if (!args.Contains(ArgumentCommandConstants.LongServerOutputSourcePath, StringComparer.OrdinalIgnoreCase))
{
newArgs.Add(ArgumentCommandConstants.LongServerOutputSourcePath);
newArgs.Add(Path.Combine(Environment.CurrentDirectory, "src"));
}
if (!args.Contains(ArgumentCommandConstants.LongServerOutputTestPath, StringComparer.OrdinalIgnoreCase))
{
newArgs.Add(ArgumentCommandConstants.LongServerOutputTestPath);
newArgs.Add(Path.Combine(Environment.CurrentDirectory, "test"));
}
}
else
{
if (!(args.Contains(ArgumentCommandConstants.ShortOutputPath, StringComparer.OrdinalIgnoreCase) ||
args.Contains(ArgumentCommandConstants.LongOutputPath, StringComparer.OrdinalIgnoreCase)))
{
newArgs.Add(ArgumentCommandConstants.ShortOutputPath);
}
newArgs.Add(Environment.CurrentDirectory);
}
}
else
{
newArgs.Add(s);
}
}
if (!newArgs.Contains(ArgumentCommandConstants.LongConfigurationValidateStrictMode, StringComparer.OrdinalIgnoreCase))
{
newArgs.Add(ArgumentCommandConstants.LongConfigurationValidateStrictMode);
}
if (!newArgs.Contains(CommandConstants.ArgumentLongVerbose, StringComparer.OrdinalIgnoreCase))
{
newArgs.Add(CommandConstants.ArgumentLongVerbose);
}
return newArgs.ToArray();
}
private static string[] SetHelpArgumentIfNeeded(
string[] args)
{
if (args.Length == 0)
{
return [CommandConstants.ArgumentShortHelp];
}
// TODO: Add multiple validations
return args;
}
}