]> git.deb.at Git - rhonda/impostor.git/commitdiff
Fix Impostor.Patcher.Cli not working after packing (#174)
authorJakub Staroń <kubastaron@hotmail.com>
Fri, 20 Nov 2020 15:26:00 +0000 (16:26 +0100)
committerGitHub <noreply@github.com>
Fri, 20 Nov 2020 15:26:00 +0000 (16:26 +0100)
src/Impostor.Patcher/Impostor.Patcher.Cli/Impostor.Patcher.Cli.csproj
src/Impostor.Patcher/Impostor.Patcher.Cli/Program.cs

index 74f32d7a17ad16e1eeae0387cd445c3e868acb48..c59fa87849d001e6be46accfad65a9f9d6d49cfd 100644 (file)
@@ -13,8 +13,7 @@
     </ItemGroup>
 
     <ItemGroup>
-        <PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20427.1" />
-        <PackageReference Include="System.CommandLine.DragonFruit" Version="0.3.0-alpha.20427.1" />
+        <PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20478.1" />
     </ItemGroup>
-    
+
 </Project>
index cdcc12cd877c04af2e8b85d75b2114653bdf2138..76653a1b5fa99fdfba94d691b7fdde9d9e9c82d1 100644 (file)
@@ -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();
 
-        /// <param name="address">IP Address of the server, will prompt if not specified</param>
-        /// <param name="name">Name for server region</param>
-        private static Task Main(string address = null, string name = AmongUsModifier.DefaultRegionName)
+        internal static Task<int> 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<string>(
+                    "--address",
+                    "IP Address of the server, will prompt if not specified"
+                ),
+                new Option<string>(
+                    "--name",
+                    () => AmongUsModifier.DefaultRegionName,
+                    "Name for server region"
+                )
+            };
 
-            if (address != null)
+            rootCommand.Handler = CommandHandler.Create<string, string>((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
+}