-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathCodeGenConsole.cs
520 lines (434 loc) · 25.2 KB
/
CodeGenConsole.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef
using Beef.CodeGen.OpenApi;
using CoreEx;
using CoreEx.Abstractions;
using McMaster.Extensions.CommandLineUtils;
using Microsoft.Extensions.Logging;
using OnRamp;
using System;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace Beef.CodeGen
{
/// <summary>
/// <b>Beef</b>-specific code-generation console that inherits from <see cref="OnRamp.Console.CodeGenConsole"/>.
/// </summary>
/// <remarks>Command line parsing: https://natemcmaster.github.io/CommandLineUtils/ </remarks>
public class CodeGenConsole : OnRamp.Console.CodeGenConsole
{
private static readonly string[] _countExtensions = [".cs", ".json", ".jsn", ".yaml", ".yml", ".xml", ".sql"];
private string _entityScript = "EntityWebApiCoreAgent.yaml";
private string _refDataScript = "RefDataCoreCrud.yaml";
private string _dataModelScript = "DataModelOnly.yaml";
private string _databaseScript = "Database.yaml";
private CommandArgument<CommandType>? _cmdArg;
private CommandArgument? _additionalArgs;
/// <summary>
/// Gets the 'Company' <see cref="CodeGeneratorArgsBase.Parameters"/> name.
/// </summary>
public const string CompanyParamName = "Company";
/// <summary>
/// Gets the 'AppName' <see cref="CodeGeneratorArgsBase.Parameters"/> name.
/// </summary>
public const string AppNameParamName = "AppName";
/// <summary>
/// Gets the 'ApiName' <see cref="CodeGeneratorArgsBase.Parameters"/> name.
/// </summary>
public const string ApiNameParamName = "ApiName";
/// <summary>
/// Gets the 'DatabaseMigrator' <see cref="CodeGeneratorArgsBase.Parameters"/> name.
/// </summary>
public const string DatabaseMigratorParamName = "DatabaseMigrator";
/// <summary>
/// Gets the default masthead text.
/// </summary>
/// <remarks>Defaults to 'Beef Code-Gen Tool' formatted using <see href="http://www.patorjk.com/software/taag/#p=display&f=Calvin%20S&t=Beef%20Code-Gen%20Tool%0A"/>.</remarks>
public const string DefaultMastheadText = @"
╔╗ ┌─┐┌─┐┌─┐ ╔═╗┌─┐┌┬┐┌─┐ ╔═╗┌─┐┌┐┌ ╔╦╗┌─┐┌─┐┬
╠╩╗├┤ ├┤ ├┤ ║ │ │ ││├┤───║ ╦├┤ │││ ║ │ ││ ││
╚═╝└─┘└─┘└ ╚═╝└─┘─┴┘└─┘ ╚═╝└─┘┘└┘ ╩ └─┘└─┘┴─┘
";
/// <summary>
/// Creates a new instance of the <see cref="CodeGenConsole"/> class defaulting to <see cref="Assembly.GetCallingAssembly"/>.
/// </summary>
/// <param name="company">The company name.</param>
/// <param name="appName">The application/domain name.</param>
/// <param name="apiName">The Web API name.</param>
/// <param name="outputDirectory">The output path/directory; defaults to the resulting <see cref="OnRamp.Console.CodeGenConsole.GetBaseExeDirectory"/> <see cref="DirectoryInfo.Parent"/>.</param>
/// <returns>The <see cref="CodeGenConsole"/> instance.</returns>
public static CodeGenConsole Create(string company, string appName, string apiName = "Api", string? outputDirectory = null) => Create([Assembly.GetCallingAssembly()], company, appName, apiName, outputDirectory);
/// <summary>
/// Creates a new instance of the <see cref="CodeGenConsole"/> class.
/// </summary>
/// <param name="assemblies">The list of additional assemblies to probe for resources.</param>
/// <param name="company">The company name.</param>
/// <param name="appName">The application/domain name.</param>
/// <param name="apiName">The Web API name.</param>
/// <param name="outputDirectory">The output path/directory; defaults to the resulting <see cref="OnRamp.Console.CodeGenConsole.GetBaseExeDirectory"/> <see cref="DirectoryInfo.Parent"/>.</param>
/// <returns>The <see cref="CodeGenConsole"/> instance.</returns>
public static CodeGenConsole Create(Assembly[] assemblies, string company, string appName, string apiName = "Api", string? outputDirectory = null)
{
var args = new CodeGeneratorArgs { OutputDirectory = string.IsNullOrEmpty(outputDirectory) ? new DirectoryInfo(GetBaseExeDirectory()).Parent : new DirectoryInfo(outputDirectory) };
args.AddAssembly(typeof(CodeGenConsole).Assembly);
args.AddAssembly(assemblies);
args.AddParameter(CompanyParamName, company ?? throw new ArgumentNullException(nameof(company)));
args.AddParameter(AppNameParamName, appName ?? throw new ArgumentNullException(nameof(appName)));
args.AddParameter(ApiNameParamName, apiName ?? throw new ArgumentNullException(nameof(apiName)));
return new CodeGenConsole(args) { BypassOnWrites = true };
}
/// <summary>
/// Initializes a new instance of the <see cref="CodeGenConsole"/> class.
/// </summary>
internal CodeGenConsole(CodeGeneratorArgs args) : base(args, OnRamp.Console.SupportedOptions.All)
{
MastheadText = DefaultMastheadText;
Args.CreateConnectionStringEnvironmentVariableName ??= csargs => $"{args.GetCompany()?.Replace(".", "_", StringComparison.InvariantCulture)}_{args.GetAppName()?.Replace(".", "_", StringComparison.InvariantCulture)}_ConnectionString";
}
/// <summary>
/// Indicates whether <see cref="CommandType.Entity"/> is supported (defaults to <c>true</c>).
/// </summary>
public bool IsEntitySupported { get; set; } = true;
/// <summary>
/// Indicates whether <see cref="CommandType.Database"/> is supported (defaults to <c>false</c>).
/// </summary>
public bool IsDatabaseSupported { get; set; } = false;
/// <summary>
/// Indicates whether <see cref="CommandType.RefData"/> is supported (defaults to <c>false</c>).
/// </summary>
public bool IsRefDataSupported { get; set; } = false;
/// <summary>
/// Indicates whether <see cref="CommandType.DataModel"/> is supported (defaults to <c>false</c>).
/// </summary>
public bool IsDataModelSupported { get; set; } = false;
/// <summary>
/// Sets the <see cref="IsEntitySupported"/>, <see cref="IsDatabaseSupported"/> and <see cref="IsRefDataSupported"/> options.
/// </summary>
/// <param name="entity">Indicates whether the entity code generation should take place.</param>
/// <param name="database">Indicates whether the database generation should take place.</param>
/// <param name="refData">Indicates whether the reference data generation should take place.</param>
/// <param name="dataModel">Indicates whether the data model generation should take place.</param>
/// <returns>The <see cref="CodeGenConsole"/> to support method chaining/fluent style.</returns>
public CodeGenConsole Supports(bool entity = true, bool database = false, bool refData = false, bool dataModel = false)
{
IsEntitySupported = entity;
IsDatabaseSupported = database;
IsRefDataSupported = refData;
IsDataModelSupported = dataModel;
return this;
}
/// <summary>
/// Sets (overrides) the execution script file or embedded resource name for the <see cref="CommandType.Database"/> (defaults to <c>EntityWebApiCoreAgent.yaml</c>).
/// </summary>
/// <param name="script">The execution script file or embedded resource name.</param>
/// <returns>The current instance to supported fluent-style method-chaining.</returns>
public CodeGenConsole EntityScript(string script)
{
_entityScript = script ?? throw new ArgumentNullException(nameof(script));
return this;
}
/// <summary>
/// Sets (overrides) the execution script file or embedded resource name for the <see cref="CommandType.DataModel"/> (defaults to <c>DataModelOnly.yaml</c>).
/// </summary>
/// <param name="script">The execution script file or embedded resource name.</param>
/// <returns>The current instance to supported fluent-style method-chaining.</returns>
public CodeGenConsole DataModelScript(string script)
{
_dataModelScript = script ?? throw new ArgumentNullException(nameof(script));
return this;
}
/// <summary>
/// Sets (overrides) the execution script file or embedded resource name for the <see cref="CommandType.RefData"/> (defaults to <c>RefDataCoreCrud.yaml</c>).
/// </summary>
/// <param name="script">The execution script file or embedded resource name.</param>
/// <returns>The current instance to supported fluent-style method-chaining.</returns>
public CodeGenConsole RefDataScript(string script)
{
_refDataScript = script ?? throw new ArgumentNullException(nameof(script));
return this;
}
/// <summary>
/// Sets (overrides) the execution script file or embedded resource name for the <see cref="CommandType.Database"/> (defaults to <c>Database.yaml</c>).
/// </summary>
/// <param name="script">The execution script file or embedded resource name.</param>
/// <returns>The current instance to supported fluent-style method-chaining.</returns>
public CodeGenConsole DatabaseScript(string script)
{
_databaseScript = script ?? throw new ArgumentNullException(nameof(script));
return this;
}
/// <summary>
/// Sets (overrides) the default database connection string.
/// </summary>
/// <param name="connectionString">The database connection string.</param>
/// <returns>The current instance to supported fluent-style method-chaining.</returns>
/// <remarks>Acts as the default; the command line option '<c>-cs|--connectionString</c>' and environment variable take precedence.</remarks>
public CodeGenConsole DatabaseConnectionString(string connectionString)
{
Args.ConnectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
return this;
}
/// <summary>
/// Add or replace the <see cref="OpenApiArgs"/> to the underlying <see cref="OnRamp.Console.CodeGenConsole.Args"/>.
/// </summary>
/// <param name="openApiArgs">The <see cref="OpenApiArgs"/>.</param>
/// <returns>The current instance to supported fluent-style method-chaining.</returns>
public CodeGenConsole WithOpenApiArgs(OpenApiArgs openApiArgs)
{
Args.Parameters[nameof(OpenApiArgs)] = openApiArgs.ThrowIfNull(nameof(openApiArgs));
return this;
}
/// <inheritdoc/>
protected override void OnBeforeExecute(CommandLineApplication app)
{
_cmdArg = app.Argument<CommandType>("command", "Execution command type.", false).IsRequired();
_additionalArgs = app.Argument("args", "Additional arguments for the 'OpenApi' command (further described).", multipleValues: true);
using var sr = Resource.GetStreamReader<CodeGenConsole>("ExtendedHelp.txt");
app.ExtendedHelpText = sr.ReadToEnd();
}
/// <inheritdoc/>
protected override ValidationResult? OnValidation(ValidationContext context)
{
var cmd = _cmdArg!.ParsedValue;
if (cmd == CommandType.All)
{
if (!string.IsNullOrEmpty(Args.ScriptFileName))
return new ValidationResult("Command 'All' is not compatible with --script; the command must be more specific when using a specified configuration file.");
if (!string.IsNullOrEmpty(Args.ConfigFileName))
return new ValidationResult("Command 'All' is not compatible with --config; the command must be more specific when using a specified configuration file.");
}
else
{
var vr = CheckCommandIsSupported(cmd, CommandType.Entity, IsEntitySupported);
vr ??= CheckCommandIsSupported(cmd, CommandType.RefData, IsRefDataSupported);
vr ??= CheckCommandIsSupported(cmd, CommandType.DataModel, IsDataModelSupported);
vr ??= CheckCommandIsSupported(cmd, CommandType.Database, IsDatabaseSupported);
if (vr != null)
return vr;
}
Args.ValidateCompanyAndAppName();
return ValidationResult.Success;
}
/// <summary>
/// Check command is supported.
/// </summary>
private static ValidationResult? CheckCommandIsSupported(CommandType act, CommandType exp, bool isSupported) => act == exp && !isSupported ? new ValidationResult($"Command '{act}' is not supported.") : null;
/// <inheritdoc/>
protected override async Task<CodeGenStatistics> OnCodeGenerationAsync()
{
OnWriteMasthead();
OnWriteHeader();
var cmd = _cmdArg!.ParsedValue;
var exedir = GetBaseExeDirectory();
var company = Args.GetCompany(false);
var appName = Args.GetAppName(false);
if (company == null || appName == null)
throw new CodeGenException($"Parameters '{CompanyParamName}' and {AppNameParamName} must be specified.");
var count = 0;
var stats = new CodeGenStatistics();
if (IsDatabaseSupported && cmd.HasFlag(CommandType.Database))
stats.Add(await ExecuteCodeGenerationAsync(_databaseScript, CodeGenFileManager.GetConfigFilename(exedir, CommandType.Database, company, appName), count++).ConfigureAwait(false));
if (IsRefDataSupported && cmd.HasFlag(CommandType.RefData))
stats.Add(await ExecuteCodeGenerationAsync(_refDataScript, CodeGenFileManager.GetConfigFilename(exedir, CommandType.RefData, company, appName), count++).ConfigureAwait(false));
if (IsEntitySupported && cmd.HasFlag(CommandType.Entity))
stats.Add(await ExecuteCodeGenerationAsync(_entityScript, CodeGenFileManager.GetConfigFilename(exedir, CommandType.Entity, company, appName), count++).ConfigureAwait(false));
if (IsDataModelSupported && cmd.HasFlag(CommandType.DataModel))
stats.Add(await ExecuteCodeGenerationAsync(_dataModelScript, CodeGenFileManager.GetConfigFilename(exedir, CommandType.DataModel, company, appName), count++).ConfigureAwait(false));
if (cmd.HasFlag(CommandType.Clean))
ExecuteClean();
if (cmd.HasFlag(CommandType.Count))
ExecuteCount();
if (cmd.HasFlag(CommandType.EndPoints))
await ExecuteEndpointsAsync(exedir, company, appName).ConfigureAwait(false);
if (cmd.HasFlag(CommandType.OpenApi))
await ExecuteOpenApiAsync(exedir).ConfigureAwait(false);
if (count > 1)
{
Args.Logger?.LogInformation("{Content}", new string('-', 80));
Args.Logger?.LogInformation("{Content}", "");
Args.Logger?.LogInformation("{Content}", $"{AppName} OVERALL. {stats.ToSummaryString()}");
Args.Logger?.LogInformation("{Content}", "");
}
return stats;
}
/// <summary>
/// Execute the selection code-generation.
/// </summary>
private async Task<CodeGenStatistics> ExecuteCodeGenerationAsync(string scriptName, string configName, int count)
{
// Update the files.
var args = new CodeGeneratorArgs();
args.CopyFrom(Args);
args.ScriptFileName ??= scriptName;
args.ConfigFileName ??= configName;
if (count > 0)
{
args.Logger?.LogInformation("{Content}", new string('-', 80));
args.Logger?.LogInformation("{Content}", "");
}
OnWriteArgs(args);
// Execute the code-generation.
var stats = await ExecuteCodeGenerationAsync(args).ConfigureAwait(false);
// Write results.
OnWriteFooter(stats);
return stats;
}
/// <summary>
/// Executes the code generation.
/// </summary>
/// <param name="args">The <see cref="CodeGeneratorArgs"/>.</param>
/// <returns>The <see cref="CodeGenStatistics"/>.</returns>
public static async Task<CodeGenStatistics> ExecuteCodeGenerationAsync(CodeGeneratorArgsBase args)
{
var cg = await OnRamp.CodeGenerator.CreateAsync<CodeGenerator>(args).ConfigureAwait(false);
var fi = new FileInfo(args.ConfigFileName ?? throw new CodeGenException("Configuration file not specified."));
return await cg.GenerateAsync(fi.FullName).ConfigureAwait(false);
}
/// <summary>
/// Executes the clean.
/// </summary>
private void ExecuteClean()
{
if (Args.OutputDirectory == null)
return;
var exclude = Args.GetParameter<string?>("exclude")?.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) ?? [];
Args.Logger?.LogInformation("{Content}", $"Cleaning: {Args.OutputDirectory.FullName}");
Args.Logger?.LogInformation("{Content}", $"Exclude: {string.Join(", ", exclude)}");
Args.Logger?.LogInformation("{Content}", string.Empty);
// Use the count logic to detemine all paths with specified exclusions.
var sw = Stopwatch.StartNew();
var dcs = new DirectoryCountStatistics(Args.OutputDirectory, exclude);
CountDirectoryAndItsChildren(dcs);
dcs?.Clean(Args.Logger!);
sw.Stop();
Args.Logger?.LogInformation("{Content}", string.Empty);
Args.Logger?.LogInformation("{Content}", $"{AppName} Complete. [{sw.Elapsed.TotalMilliseconds}ms, Files: {dcs?.GeneratedTotalFileCount ?? 0}]");
Args.Logger?.LogInformation("{Content}", string.Empty);
}
/// <summary>
/// Executes the count.
/// </summary>
private void ExecuteCount()
{
if (Args.OutputDirectory == null)
return;
var exclude = Args.GetParameter<string?>("exclude")?.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) ?? [];
Args.Logger?.LogInformation("{Content}", $"Counting: {Args.OutputDirectory.FullName}");
Args.Logger?.LogInformation("{Content}", $"Include: {string.Join(", ", _countExtensions)}");
Args.Logger?.LogInformation("{Content}", $"Exclude: {string.Join(", ", exclude)}");
Args.Logger?.LogInformation("{Content}", string.Empty);
var sw = Stopwatch.StartNew();
var dcs = new DirectoryCountStatistics(Args.OutputDirectory, exclude);
CountDirectoryAndItsChildren(dcs);
var columnLength = Math.Max(dcs.TotalLineCount.ToString().Length, 5);
dcs.Write(Args.Logger!, columnLength, 0, dcs.Directory.Parent is null ? 0 : dcs.Directory.Parent.FullName.Length + 1);
Args.Logger?.LogInformation("{Content}", string.Empty);
Args.Logger?.LogInformation("{Content}", $"{AppName} Complete. [{sw.Elapsed.TotalMilliseconds}ms]");
Args.Logger?.LogInformation("{Content}", string.Empty);
}
/// <summary>
/// Count the directory and its children (recursive).
/// </summary>
private static void CountDirectoryAndItsChildren(DirectoryCountStatistics dcs)
{
foreach (var di in dcs.Directory.EnumerateDirectories())
{
if (di.Name.Equals("obj", StringComparison.InvariantCultureIgnoreCase) || di.Name.Equals("bin", StringComparison.InvariantCultureIgnoreCase) || di.Name.StartsWith('.'))
continue;
if (dcs.Exclude.Any(x => di.Name.Contains(x, StringComparison.InvariantCultureIgnoreCase)))
continue;
CountDirectoryAndItsChildren(dcs.AddChildDirectory(di));
}
foreach (var fi in dcs.Directory.EnumerateFiles())
{
if (!_countExtensions.Contains(fi.Extension, StringComparer.OrdinalIgnoreCase))
continue;
using var sr = fi.OpenText();
while (sr.ReadLine() is not null)
{
dcs.IncrementLineCount();
}
dcs.IncrementFileCount();
}
}
/// <summary>
/// Executes the endpoints.
/// </summary>
private async Task ExecuteEndpointsAsync(string? exedir, string company, string appName)
{
var sw = Stopwatch.StartNew();
EndPointStatistics endpoints;
if (IsEntitySupported)
{
// Writer header.
var filename = CodeGenFileManager.GetConfigFilename(exedir!, CommandType.Entity, company, appName);
Logger?.LogInformation("{Content}", $"Config: {filename}");
var root = await LoadConfigAsync(CodeGenFileManager.GetConfigFilename(exedir!, CommandType.Entity, company, appName)).ConfigureAwait(false);
endpoints = new EndPointStatistics();
endpoints.AddEntityEndPoints(root);
Logger?.LogInformation("{Content}", $"Endpoints: {(endpoints.Count == 0 ? "none" : endpoints.Count)}");
Logger?.LogInformation("{Content}", string.Empty);
endpoints.WriteTabulated(Args.Logger!);
if (IsRefDataSupported)
{
Args.Logger!.LogInformation("{Content}", new string('-', 80));
Args.Logger!.LogInformation("{Content}", string.Empty);
}
}
if (IsRefDataSupported)
{
var filename = CodeGenFileManager.GetConfigFilename(exedir!, CommandType.RefData, company, appName);
Logger?.LogInformation("{Content}", $"Config: {filename}");
var root = await LoadConfigAsync(CodeGenFileManager.GetConfigFilename(exedir!, CommandType.RefData, company, appName)).ConfigureAwait(false);
endpoints = new EndPointStatistics();
endpoints.AddRefDataEndPoints(root);
Logger?.LogInformation("{Content}", $"Endpoints: {(endpoints.Count == 0 ? "none" : endpoints.Count)}");
Logger?.LogInformation("{Content}", string.Empty);
endpoints.WriteTabulated(Args.Logger!);
}
if (!IsEntitySupported && !IsRefDataSupported)
Args.Logger?.LogInformation("{Content}", "No EndPoints have been configured.");
Args.Logger?.LogInformation("{Content}", string.Empty);
Args.Logger?.LogInformation("{Content}", $"{AppName} Complete. [{sw.Elapsed.TotalMilliseconds}ms]");
Args.Logger?.LogInformation("{Content}", string.Empty);
}
/// <summary>
/// Load the configuration.
/// </summary>
private async Task<Config.Entity.CodeGenConfig> LoadConfigAsync(string filename)
{
// Load the configuration.
var args = new CodeGeneratorArgs();
args.CopyFrom(Args);
args.ScriptFileName ??= _entityScript;
args.ConfigFileName ??= filename;
var cg = await OnRamp.CodeGenerator.CreateAsync<CodeGenerator>(args).ConfigureAwait(false);
return (Config.Entity.CodeGenConfig)await cg.LoadConfigAsync().ConfigureAwait(false);
}
/// <summary>
/// Execute the OpenAPI processing.
/// </summary>
private async Task ExecuteOpenApiAsync(string exedir)
{
if (_additionalArgs!.Values.Count != 1)
throw new CodeGenException("The OpenAPI document path must be specified as the only argument.");
Args.Logger?.LogInformation("{Content}", " ** Code-generation of temporary entity YAML requested **");
// Read in the specified document.
var args = new CodeGeneratorArgs();
args.CopyFrom(Args);
args.OutputDirectory = new DirectoryInfo(exedir!);
var oac = await OpenApiConverter.ReadAsync(args, _additionalArgs.Value!).ConfigureAwait(false);
// Convert the OpenAPI document and generate the Beef YAML.
var fi = await oac.ConvertAsync().ConfigureAwait(false);
// Done, boom!
Args.Logger?.LogInformation("{Content}", string.Empty);
Args.Logger?.LogWarning("{Content}", $"Temporary entity file created: {fi.FullName}");
Args.Logger?.LogInformation("{Content}", string.Empty);
Args.Logger?.LogInformation("{Content}", "Copy and paste generated contents into their respective files and amend accordingly.");
Args.Logger?.LogInformation("{Content}", $"Once complete it is recommended that the '{fi.Name}' file is deleted, as it is otherwise not used.");
}
}
}