Skip to content

Commit

Permalink
asyncapi#196 formatting and readme wording
Browse files Browse the repository at this point in the history
  • Loading branch information
Senn Geerts authored and Senn Geerts committed Jul 13, 2024
1 parent ba8dd8e commit 3d6c0ea
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
12 changes: 6 additions & 6 deletions src/AsyncAPI.Saunter.Generator.Cli/ToFile/ToFileCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ internal class ToFileCommand(ILogger<ToFileCommand> logger, IEnvironmentBuilder
/// Retrieves AsyncAPI spec from a startup assembly and writes to file.
/// </summary>
/// <param name="startupassembly">relative path to the application's startup assembly</param>
/// <param name="output">-o,relative path where the AsyncAPI will be output [defaults to stdout]</param>
/// <param name="doc">-d,name(s) of the AsyncAPI documents you want to retrieve, as configured in your startup class [defaults to all documents]</param>
/// <param name="format">exports AsyncAPI in json and/or yml format [defaults to json]</param>
/// <param name="filename">defines the file name template, {document} and {extension} template variables can be used [defaults to "{document}_asyncapi.{extension}\"]</param>
/// <param name="env">define environment variable(s) for the application. Formatted as a comma separated list of key=value pairs or just key for flags</param>
/// <param name="output">-o,relative path where the AsyncAPI documents will be exported to</param>
/// <param name="doc">-d,name(s) of the AsyncAPI documents you want to export as configured in your startup class. To export all documents using null.</param>
/// <param name="format">exports AsyncAPI in json and/or yml format</param>
/// <param name="filename">defines the file name template, {document} and {extension} template variables can be used</param>
/// <param name="env">define environment variable(s) for the application. Formatted as a comma separated list of _key=value_ pairs</param>
[Command("tofile")]
public int ToFile([Argument] string startupassembly, string output = "./", string doc = null, string format = "json", string filename = DEFAULT_FILENAME, string env = "")
{
Expand Down Expand Up @@ -68,6 +68,6 @@ public int ToFile([Argument] string startupassembly, string output = "./", strin
}
}

return 1;
return 0;
}
}
12 changes: 6 additions & 6 deletions src/AsyncAPI.Saunter.Generator.Cli/readme.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
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.
14 changes: 7 additions & 7 deletions test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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]
Expand All @@ -42,11 +42,11 @@ Retrieves AsyncAPI spec from a startup assembly and writes to file.
[0] <string> relative path to the application's startup assembly

Options:
-o|--output <string> relative path where the AsyncAPI will be output [defaults to stdout] (Default: "./")
-d|--doc <string> name(s) of the AsyncAPI documents you want to retrieve as configured in your startup class [defaults to all documents] (Default: null)
--format <string> exports AsyncAPI in json and/or yml format [defaults to json] (Default: "json")
--filename <string> defines the file name template, {document} and {extension} template variables can be used [defaults to "{document}_asyncapi.{extension}\"] (Default: "{document}_asyncapi.{extension}")
--env <string> 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 <string> relative path where the AsyncAPI documents will be exported to (Default: "./")
-d|--doc <string> 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 <string> exports AsyncAPI in json and/or yml format (Default: "json")
--filename <string> defines the file name template, {document} and {extension} template variables can be used (Default: "{document}_asyncapi.{extension}")
--env <string> define environment variable(s) for the application. Formatted as a comma separated list of _key=value_ pairs (Default: "")
""", StringCompareShould.IgnoreLineEndings);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down

0 comments on commit 3d6c0ea

Please sign in to comment.