From 4ebba13076dc25ddf1f9820d6dcf30f3955dd4ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jakub=20Staro=C5=84?= Date: Fri, 20 Nov 2020 16:26:00 +0100 Subject: [PATCH] Fix Impostor.Patcher.Cli not working after packing (#174) --- .../Impostor.Patcher.Cli.csproj | 5 +- .../Impostor.Patcher.Cli/Program.cs | 52 +++++++++++++------ 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/Impostor.Patcher/Impostor.Patcher.Cli/Impostor.Patcher.Cli.csproj b/src/Impostor.Patcher/Impostor.Patcher.Cli/Impostor.Patcher.Cli.csproj index 74f32d7..c59fa87 100644 --- a/src/Impostor.Patcher/Impostor.Patcher.Cli/Impostor.Patcher.Cli.csproj +++ b/src/Impostor.Patcher/Impostor.Patcher.Cli/Impostor.Patcher.Cli.csproj @@ -13,8 +13,7 @@ - - + - + diff --git a/src/Impostor.Patcher/Impostor.Patcher.Cli/Program.cs b/src/Impostor.Patcher/Impostor.Patcher.Cli/Program.cs index cdcc12c..76653a1 100644 --- a/src/Impostor.Patcher/Impostor.Patcher.Cli/Program.cs +++ b/src/Impostor.Patcher/Impostor.Patcher.Cli/Program.cs @@ -1,4 +1,6 @@ using System; +using System.CommandLine; +using System.CommandLine.Invocation; using System.Threading.Tasks; using Impostor.Patcher.Shared; using Impostor.Patcher.Shared.Events; @@ -9,27 +11,43 @@ namespace Impostor.Patcher.Cli { private static readonly AmongUsModifier Modifier = new AmongUsModifier(); - /// IP Address of the server, will prompt if not specified - /// Name for server region - private static Task Main(string address = null, string name = AmongUsModifier.DefaultRegionName) + internal static Task Main(string[] args) { - Modifier.RegionName = name; - Modifier.Error += ModifierOnError; - Modifier.Saved += ModifierOnSaved; - - Console.WriteLine("Welcome to Impostor"); - - if (Modifier.TryLoadRegionInfo(out var regionInfo)) + var rootCommand = new RootCommand { - Console.WriteLine($"Currently selected region: {regionInfo.Name} ({regionInfo.Ping}, {regionInfo.Servers.Count} server(s))"); - } + new Option( + "--address", + "IP Address of the server, will prompt if not specified" + ), + new Option( + "--name", + () => AmongUsModifier.DefaultRegionName, + "Name for server region" + ) + }; - if (address != null) + rootCommand.Handler = CommandHandler.Create((address, name) => { - return Modifier.SaveIpAsync(address); - } + Modifier.RegionName = name; + Modifier.Error += ModifierOnError; + Modifier.Saved += ModifierOnSaved; + + Console.WriteLine("Welcome to Impostor"); + + if (Modifier.TryLoadRegionInfo(out var regionInfo)) + { + Console.WriteLine($"Currently selected region: {regionInfo.Name} ({regionInfo.Ping}, {regionInfo.Servers.Count} server(s))"); + } + + if (address != null) + { + return Modifier.SaveIpAsync(address); + } + + return PromptAsync(); + }); - return PromptAsync(); + return rootCommand.InvokeAsync(args); } private static void ModifierOnSaved(object sender, SavedEventArgs e) @@ -67,4 +85,4 @@ namespace Impostor.Patcher.Cli } } } -} \ No newline at end of file +} -- 2.39.5