Skip to content

Commit

Permalink
Merge pull request #233 from nenoNaninu/use_cocona
Browse files Browse the repository at this point in the history
use Cocona instead of ConsoleAppFramework
  • Loading branch information
nenoNaninu authored Nov 26, 2024
2 parents b3d16ea + d8fa9dd commit a45508d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Cocona" Version="2.2.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.8.0" />
Expand All @@ -19,7 +20,6 @@
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="ConsoleAppFramework" Version="4.2.4" />
<PackageVersion Include="MessagePack" Version="2.5.192" />
<PackageVersion Include="MessagePack.AspNetCoreMvcFormatter" Version="2.5.187" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,10 @@ export type Type4 = {
### Transpile the Types Contained in Referenced Assemblies
By default, only types defined in the project specified by the `--project` option are targeted for transpiling.
By passing the `-asm true` option, types contained in project/package reference assemblies will also be targeted for transpiling.
By passing the `--asm true` option, types contained in project/package reference assemblies will also be targeted for transpiling.
```bash
tapper --project path/to/Xxx.csproj --output outdir -asm true
tapper --project path/to/Xxx.csproj --output outdir --asm true
```
## Analyzer
Expand Down
28 changes: 14 additions & 14 deletions src/Tapper.Generator/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Cocona;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
using Microsoft.CodeAnalysis;
Expand All @@ -11,34 +12,33 @@

namespace Tapper;

public class App : ConsoleAppBase
public class App : CoconaConsoleAppBase
{
private readonly ILogger<App> _logger;
private readonly Microsoft.Extensions.Logging.ILogger _logger;

public App(ILogger<App> logger)
public App(ILoggerFactory loggerFactory)
{
_logger = logger;
_logger = loggerFactory.CreateLogger("Tapper");
}

[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("i", "Indent size")]
[Option('i', Description ="Indent size")]
int indent = 4,
[Option("asm", "The flag whether to extend the transpile target to the referenced assembly.")]
[Option("asm", Description ="The flag whether to extend the transpile target to the referenced assembly.")]
bool assemblies = false,
[Option("s", "JSON (default) / 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 / 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 / name / nameCamel / NamePascal / union / unionCamel / UnionPascal")]
EnumStyle @enum = EnumStyle.Value,
[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));
Expand Down
11 changes: 10 additions & 1 deletion src/Tapper.Generator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
using Cocona;
using Microsoft.Build.Locator;
using Microsoft.Extensions.Logging;
using Tapper;

MSBuildLocator.RegisterDefaults();

var app = ConsoleApp.Create(args);
var builder = CoconaApp.CreateBuilder();

builder.Logging.AddSimpleConsole(options =>
{
options.SingleLine = true;
});

var app = builder.Build();

app.AddCommands<App>();

Expand Down
2 changes: 1 addition & 1 deletion src/Tapper.Generator/Tapper.Generator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cocona" />
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" />
<PackageReference Include="ConsoleAppFramework" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ConsoleAppFramework" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
Expand Down
4 changes: 2 additions & 2 deletions tests/Tapper.Tests.AsmReference/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public async Task Test1()

private static async Task ExecCommand(string generatorProject, string projectFullPath, string outputFullPath, ITestOutputHelper outputHelper)
{
outputHelper.WriteLine($"run --project {generatorProject} --framework net8.0 -- --project {projectFullPath} --output {outputFullPath} -asm true");
outputHelper.WriteLine($"run --project {generatorProject} --framework net8.0 -- --project {projectFullPath} --output {outputFullPath} --asm true");
var startInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"run --project {generatorProject} --framework net8.0 -- --project {projectFullPath} --output {outputFullPath} -asm true"
Arguments = $"run --project {generatorProject} --framework net8.0 -- --project {projectFullPath} --output {outputFullPath} --asm true"
};

var process = new Process { StartInfo = startInfo };
Expand Down

0 comments on commit a45508d

Please sign in to comment.