From 60a8c29fdd7bc56811006e4e850ae0b83635beb6 Mon Sep 17 00:00:00 2001 From: Eveldee Date: Fri, 4 Jun 2021 19:06:13 +0200 Subject: [PATCH] Add CliFx support --- .../Akari.Prototype.Server.csproj | 1 + .../Cli/Commands/MainCommand.cs | 19 +++++++++++++++++++ Akari.Prototype.Server/Program.cs | 11 +++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 Akari.Prototype.Server/Cli/Commands/MainCommand.cs diff --git a/Akari.Prototype.Server/Akari.Prototype.Server.csproj b/Akari.Prototype.Server/Akari.Prototype.Server.csproj index 5848232..f3d3904 100644 --- a/Akari.Prototype.Server/Akari.Prototype.Server.csproj +++ b/Akari.Prototype.Server/Akari.Prototype.Server.csproj @@ -9,6 +9,7 @@ + diff --git a/Akari.Prototype.Server/Cli/Commands/MainCommand.cs b/Akari.Prototype.Server/Cli/Commands/MainCommand.cs new file mode 100644 index 0000000..bbbb0d8 --- /dev/null +++ b/Akari.Prototype.Server/Cli/Commands/MainCommand.cs @@ -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()); + } + } +} diff --git a/Akari.Prototype.Server/Program.cs b/Akari.Prototype.Server/Program.cs index b9867dd..071759c 100644 --- a/Akari.Prototype.Server/Program.cs +++ b/Akari.Prototype.Server/Program.cs @@ -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 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.