Add CliFx support

This commit is contained in:
2021-06-04 19:06:13 +02:00
parent a554706903
commit 60a8c29fdd
3 changed files with 29 additions and 2 deletions

View File

@@ -9,6 +9,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CliFx" Version="2.0.4" />
<PackageReference Include="Grpc.AspNetCore" Version="2.34.0" />
<PackageReference Include="Isopoh.Cryptography.Argon2" Version="1.1.10" />
</ItemGroup>

View File

@@ -0,0 +1,19 @@
using CliFx;
using CliFx.Attributes;
using CliFx.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Akari.Prototype.Server.Cli.Commands
{
[Command]
public class MainCommand : ICommand
{
public async ValueTask ExecuteAsync(IConsole console)
{
await Program.AspMain(Array.Empty<string>());
}
}
}

View File

@@ -1,4 +1,5 @@
using Akari.Prototype.Server.Options;
using CliFx;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -15,7 +16,13 @@ namespace Akari.Prototype.Server
{
public class Program
{
public static void Main(string[] args)
public static async Task<int> Main() =>
await new CliApplicationBuilder()
.AddCommandsFromThisAssembly()
.Build()
.RunAsync();
public static async Task AspMain(string[] args)
{
var host = CreateHostBuilder(args).Build();
@@ -27,7 +34,7 @@ namespace Akari.Prototype.Server
Directory.CreateDirectory(akariOptions.DataPath);
}
host.Run();
await host.RunAsync();
}
// Additional configuration is required to successfully run gRPC on macOS.