From 3d6c0ea1b5c323bd928de0c4bbff93b82f60d999 Mon Sep 17 00:00:00 2001 From: Senn Geerts Date: Sat, 13 Jul 2024 20:37:16 +0200 Subject: [PATCH] #196 formatting and readme wording --- .../ToFile/ToFileCommand.cs | 12 ++++++------ src/AsyncAPI.Saunter.Generator.Cli/readme.md | 12 ++++++------ .../IntegrationTests.cs | 14 +++++++------- .../Specs/ExpectedSpecFiles.cs | 6 +----- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/AsyncAPI.Saunter.Generator.Cli/ToFile/ToFileCommand.cs b/src/AsyncAPI.Saunter.Generator.Cli/ToFile/ToFileCommand.cs index 0a62c43d..91055b47 100644 --- a/src/AsyncAPI.Saunter.Generator.Cli/ToFile/ToFileCommand.cs +++ b/src/AsyncAPI.Saunter.Generator.Cli/ToFile/ToFileCommand.cs @@ -13,11 +13,11 @@ internal class ToFileCommand(ILogger logger, IEnvironmentBuilder /// Retrieves AsyncAPI spec from a startup assembly and writes to file. /// /// relative path to the application's startup assembly - /// -o,relative path where the AsyncAPI will be output [defaults to stdout] - /// -d,name(s) of the AsyncAPI documents you want to retrieve, as configured in your startup class [defaults to all documents] - /// exports AsyncAPI in json and/or yml format [defaults to json] - /// defines the file name template, {document} and {extension} template variables can be used [defaults to "{document}_asyncapi.{extension}\"] - /// define environment variable(s) for the application. Formatted as a comma separated list of key=value pairs or just key for flags + /// -o,relative path where the AsyncAPI documents will be exported to + /// -d,name(s) of the AsyncAPI documents you want to export as configured in your startup class. To export all documents using null. + /// exports AsyncAPI in json and/or yml format + /// defines the file name template, {document} and {extension} template variables can be used + /// define environment variable(s) for the application. Formatted as a comma separated list of _key=value_ pairs [Command("tofile")] public int ToFile([Argument] string startupassembly, string output = "./", string doc = null, string format = "json", string filename = DEFAULT_FILENAME, string env = "") { @@ -68,6 +68,6 @@ public int ToFile([Argument] string startupassembly, string output = "./", strin } } - return 1; + return 0; } } diff --git a/src/AsyncAPI.Saunter.Generator.Cli/readme.md b/src/AsyncAPI.Saunter.Generator.Cli/readme.md index b5ee1273..01030989 100644 --- a/src/AsyncAPI.Saunter.Generator.Cli/readme.md +++ b/src/AsyncAPI.Saunter.Generator.Cli/readme.md @@ -1,17 +1,17 @@ # AsyncApi Generator.Cli Tool -A dotnet tool to generate AsyncAPI specification files based of a dotnet DLL (The application itself). +A dotnet tool to generate AsyncAPI specification files based of a dotnet assembly (The application itself). ## Tool usage ``` dotnet asyncapi tofile [startup-assembly] --output [output-path] --format [json,yml,yaml] --doc [asyncapi-document-name] ``` -- _startup-assembly_: the file path to the entrypoint dotnet DLL that hosts AsyncAPI document(s). +- _startup-assembly_: the file path to the dotnet startup assembly (DLL) that hosts AsyncAPI document(s). ## Tool options - _--doc_: The name of the AsyncAPI document as defined in the startup class by the ```.ConfigureNamedAsyncApi()```-method. If only ```.AddAsyncApiSchemaGeneration()``` is used, the document is unnamed and will always be exported. If not specified, all documents will be exported. -- _--output_: relative path where the AsyncAPI will be output [defaults to stdout] -- _--filename_: the template for the outputted file names. Default: "{document}_asyncapi.{extension}" -- _--format_: the output formats to generate, can be a combination of json, yml and/or yaml. +- _--output_: relative path where the AsyncAPI documents will be exported to (Default: the csproj root "./"). +- _--filename_: the template for the outputted file names (Default: "{document}_asyncapi.{extension}"). +- _--format_: the output formats to generate, can be a combination of json, yml and/or yaml (Default: "json"). - _--env_: define environment variable(s) for the application. Formatted as a comma separated list of _key=value_ pairs, example: ```ASPNETCORE_ENVIRONMENT=AsyncAPI,CONNECT_TO_DATABASE=false```. ## Install the Generator.Cli dotnet Tool @@ -24,4 +24,4 @@ Want to learn more about .NET tools? Or want to install it local using a manifes [Check out this Microsoft page on how to manage .NET tools](https://learn.microsoft.com/en-us/dotnet/core/tools/global-tools) ## Internals -How does the tool work internally? It tries to exact an ```IServiceProvider``` from the provided _startup-assembly_ and exports AsyncApiDocument(s) as registered in the services provider. \ No newline at end of file +How does the tool work internally? It tries to exact an ```IServiceProvider``` from the provided _startup-assembly_ and exports AsyncApiDocument(s) as registered with the services provider. \ No newline at end of file diff --git a/test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs b/test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs index 52cb62e7..7b5c6fb6 100644 --- a/test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs +++ b/test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs @@ -5,7 +5,7 @@ namespace AsyncAPI.Saunter.Generator.Cli.Tests; public class IntegrationTests(ITestOutputHelper output) { - private string RunTool(string args, int expectedExitCode = 1) + private string RunTool(string args, int expectedExitCode = 0) { using var outWriter = new StringWriter(); using var errorWriter = new StringWriter(); @@ -31,7 +31,7 @@ private string RunTool(string args, int expectedExitCode = 1) [Fact] public void DefaultCallPrintsCommandInfo() { - var stdOut = RunTool("tofile", 0).Trim(); + var stdOut = RunTool("tofile").Trim(); stdOut.ShouldBe(""" Usage: tofile [arguments...] [options...] [-h|--help] [--version] @@ -42,11 +42,11 @@ Retrieves AsyncAPI spec from a startup assembly and writes to file. [0] relative path to the application's startup assembly Options: - -o|--output relative path where the AsyncAPI will be output [defaults to stdout] (Default: "./") - -d|--doc name(s) of the AsyncAPI documents you want to retrieve as configured in your startup class [defaults to all documents] (Default: null) - --format exports AsyncAPI in json and/or yml format [defaults to json] (Default: "json") - --filename defines the file name template, {document} and {extension} template variables can be used [defaults to "{document}_asyncapi.{extension}\"] (Default: "{document}_asyncapi.{extension}") - --env define environment variable(s) for the application. Formatted as a comma separated list of key=value pairs or just key for flags (Default: "") + -o|--output relative path where the AsyncAPI documents will be exported to (Default: "./") + -d|--doc name(s) of the AsyncAPI documents you want to export as configured in your startup class. To export all documents using null. (Default: null) + --format exports AsyncAPI in json and/or yml format (Default: "json") + --filename defines the file name template, {document} and {extension} template variables can be used (Default: "{document}_asyncapi.{extension}") + --env define environment variable(s) for the application. Formatted as a comma separated list of _key=value_ pairs (Default: "") """, StringCompareShould.IgnoreLineEndings); } diff --git a/test/AsyncAPI.Saunter.Generator.Cli.Tests/Specs/ExpectedSpecFiles.cs b/test/AsyncAPI.Saunter.Generator.Cli.Tests/Specs/ExpectedSpecFiles.cs index aa6ed033..0d569e3a 100644 --- a/test/AsyncAPI.Saunter.Generator.Cli.Tests/Specs/ExpectedSpecFiles.cs +++ b/test/AsyncAPI.Saunter.Generator.Cli.Tests/Specs/ExpectedSpecFiles.cs @@ -1,8 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace AsyncAPI.Saunter.Generator.Cli.Tests; +namespace AsyncAPI.Saunter.Generator.Cli.Tests; public static class ExpectedSpecFiles {