From c9e06192a92636f19264a0e12befa28526349177 Mon Sep 17 00:00:00 2001 From: nenoNaninu Date: Wed, 27 Nov 2024 10:51:55 +0900 Subject: [PATCH] use Cocona instead of ConsoleAppFramework --- Directory.Packages.props | 2 +- .../App.cs | 22 +++++++++---------- .../Program.cs | 11 +++++++++- ...SignalR.Client.TypeScript.Generator.csproj | 2 +- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 4bea8aa..33ff25a 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,6 +6,7 @@ + @@ -23,7 +24,6 @@ - diff --git a/src/TypedSignalR.Client.TypeScript.Generator/App.cs b/src/TypedSignalR.Client.TypeScript.Generator/App.cs index e876849..6769bcf 100644 --- a/src/TypedSignalR.Client.TypeScript.Generator/App.cs +++ b/src/TypedSignalR.Client.TypeScript.Generator/App.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Cocona; using Microsoft.Build.Framework; using Microsoft.Build.Logging; using Microsoft.CodeAnalysis; @@ -14,7 +15,7 @@ namespace TypedSignalR.Client.TypeScript; -public class App : ConsoleAppBase +public class App : CoconaConsoleAppBase { private readonly ILogger _logger; @@ -23,25 +24,24 @@ public App(ILogger logger) _logger = logger; } - [RootCommand] public async Task Transpile( - [Option("p", "Path to the project file (XXX.csproj)")] + [Option('p', Description = "Path to the project file (XXX.csproj)")] string project, - [Option("o", "Output directory")] + [Option('o', Description ="Output directory")] string output, - [Option("eol", "lf / crlf / cr")] + [Option("eol", Description ="lf / crlf / cr")] NewLineOption newLine = NewLineOption.Lf, - [Option("asm", "Flag whether to extend the transpile target to the referenced assembly.")] + [Option("asm", Description ="Flag whether to extend the transpile target to the referenced assembly.")] bool assemblies = false, - [Option("s", "JSON / MessagePack : The output type will be suitable for the selected serializer.")] + [Option('s', Description ="JSON / MessagePack : The output type will be suitable for the selected serializer.")] SerializerOption serializer = SerializerOption.Json, - [Option("n", "camelCase (default) / PascalCase / none (The name in C# is used as it is.)")] + [Option('n', Description ="camelCase (default) / PascalCase / none (The name in C# is used as it is.)")] NamingStyle namingStyle = NamingStyle.CamelCase, - [Option("en", "value (default) / name / nameCamel / NamePascal / union / unionCamel / UnionPascal")] + [Option(Description ="value (default) / name / nameCamel / NamePascal / union / unionCamel / UnionPascal")] EnumStyle @enum = EnumStyle.Value, - [Option("m", "camelCase (default) / PascalCase / none (The name in C# is used as it is.)")] + [Option('m', Description = "camelCase (default) / PascalCase / none (The name in C# is used as it is.)")] MethodStyle method = MethodStyle.CamelCase, - [Option("attr", "The flag whether attributes such as JsonPropertyName should affect transpilation.")] + [Option("attr", Description ="The flag whether attributes such as JsonPropertyName should affect transpilation.")] bool attribute = true) { _logger.Log(LogLevel.Information, "Start loading the csproj of {path}.", Path.GetFullPath(project)); diff --git a/src/TypedSignalR.Client.TypeScript.Generator/Program.cs b/src/TypedSignalR.Client.TypeScript.Generator/Program.cs index bc4b711..5d149b0 100644 --- a/src/TypedSignalR.Client.TypeScript.Generator/Program.cs +++ b/src/TypedSignalR.Client.TypeScript.Generator/Program.cs @@ -1,9 +1,18 @@ +using Cocona; using Microsoft.Build.Locator; +using Microsoft.Extensions.Logging; using TypedSignalR.Client.TypeScript; MSBuildLocator.RegisterDefaults(); -var app = ConsoleApp.Create(args); +var builder = CoconaApp.CreateBuilder(); + +builder.Logging.AddSimpleConsole(options => +{ + options.SingleLine = true; +}); + +var app = builder.Build(); app.AddCommands(); diff --git a/src/TypedSignalR.Client.TypeScript.Generator/TypedSignalR.Client.TypeScript.Generator.csproj b/src/TypedSignalR.Client.TypeScript.Generator/TypedSignalR.Client.TypeScript.Generator.csproj index ab2bbaa..6d5d7d5 100644 --- a/src/TypedSignalR.Client.TypeScript.Generator/TypedSignalR.Client.TypeScript.Generator.csproj +++ b/src/TypedSignalR.Client.TypeScript.Generator/TypedSignalR.Client.TypeScript.Generator.csproj @@ -22,7 +22,7 @@ - +