forked from asyncapi/saunter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
asyncapi#196 Tool rewrite to make its components testable, removed Sw…
…achbuckle copy/paste code
- Loading branch information
Senn Geerts
authored and
Senn Geerts
committed
Jul 9, 2024
1 parent
a746e4d
commit 8e7a01f
Showing
19 changed files
with
290 additions
and
928 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
195 changes: 0 additions & 195 deletions
195
src/AsyncAPI.Saunter.Generator.Cli/Commands/TofileInternal.cs
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
src/AsyncAPI.Saunter.Generator.Cli/Internal/DependencyResolver.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,17 @@ | ||
using AsyncApi.Saunter.Generator.Cli.Commands; | ||
using AsyncApi.Saunter.Generator.Cli.SwashbuckleImport; | ||
using AsyncAPI.Saunter.Generator.Cli.Internal; | ||
using AsyncAPI.Saunter.Generator.Cli.ToFile; | ||
using ConsoleAppFramework; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
DependencyResolver.Init(); | ||
var services = new ServiceCollection(); | ||
services.AddLogging(builder => builder.AddSimpleConsole(x => x.SingleLine = true).SetMinimumLevel(LogLevel.Trace)); | ||
services.AddToFileCommand(); | ||
|
||
// Helper to simplify command line parsing etc. | ||
var runner = new CommandRunner("dotnet asyncapi", "AsyncAPI Command Line Tools", Console.Out); | ||
using var serviceProvider = services.BuildServiceProvider(); | ||
var logger = serviceProvider.GetRequiredService<ILogger<Program>>(); | ||
ConsoleApp.LogError = msg => logger.LogError(msg); | ||
ConsoleApp.ServiceProvider = serviceProvider; | ||
|
||
// NOTE: The "dotnet asyncapi tofile" command does not serve the request directly. Instead, it invokes a corresponding | ||
// command (called _tofile) via "dotnet exec" so that the runtime configuration (*.runtimeconfig & *.deps.json) of the | ||
// provided startupassembly can be used instead of the tool's. This is neccessary to successfully load the | ||
// startupassembly and it's transitive dependencies. See https://github.com/dotnet/coreclr/issues/13277 for more. | ||
|
||
// > dotnet asyncapi tofile ... | ||
runner.SubCommand("tofile", "retrieves AsyncAPI from a startup assembly, and writes to file ", c => | ||
{ | ||
c.Argument(StartupAssemblyArgument, "relative path to the application's startup assembly"); | ||
c.Option(DocOption, "name(s) of the AsyncAPI documents you want to retrieve, as configured in your startup class [defaults to all documents]"); | ||
c.Option(OutputOption, "relative path where the AsyncAPI will be output [defaults to stdout]"); | ||
c.Option(FileNameOption, "defines the file name template, {document} and {extension} template variables can be used [defaults to \"{document}_asyncapi.{extension}\"]"); | ||
c.Option(FormatOption, "exports AsyncAPI in json and/or yml format [defaults to json]"); | ||
c.Option(EnvOption, "define environment variable(s) for the application during generation of the AsyncAPI files [defaults to empty, can be used to define for example ASPNETCORE_ENVIRONMENT]"); | ||
c.OnRun(Tofile.Run(args)); | ||
}); | ||
|
||
// > dotnet asyncapi _tofile ... (* should only be invoked via "dotnet exec") | ||
runner.SubCommand("_tofile", "", c => | ||
{ | ||
c.Argument(StartupAssemblyArgument, ""); | ||
c.Option(DocOption, ""); | ||
c.Option(OutputOption, ""); | ||
c.Option(FileNameOption, ""); | ||
c.Option(FormatOption, ""); | ||
c.Option(EnvOption, ""); | ||
c.OnRun(TofileInternal.Run); | ||
}); | ||
|
||
return runner.Run(args); | ||
var app = ConsoleApp.Create(); | ||
app.Add<ToFileCommand>(); | ||
app.Run(args); |
Oops, something went wrong.