From 66da004e5f8c607678e73abff67b3c8dee895f9a Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Mon, 26 Aug 2024 20:19:51 -0500 Subject: [PATCH] Add CLI verb for running a game --- .../CommandLineOptions.cs | 10 ++++++++++ .../CommandLineService.cs | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/LANCommander.Launcher.Models/CommandLineOptions.cs b/LANCommander.Launcher.Models/CommandLineOptions.cs index 96cea74e..a4ef5071 100644 --- a/LANCommander.Launcher.Models/CommandLineOptions.cs +++ b/LANCommander.Launcher.Models/CommandLineOptions.cs @@ -50,6 +50,16 @@ namespace LANCommander.Launcher.Models public Guid GameId { get; set; } } + [Verb("Run", HelpText = "Start a game")] + public class RunCommandLineOptions + { + [Option("GameId", HelpText = "The GUID of the game to run")] + public Guid GameId { get; set; } + + [Option("ActionId", HelpText = "The GUID of the action to run")] + public Guid ActionId { get; set; } + } + [Verb("Sync", HelpText = "Sync library items from the server")] public class SyncCommandLineOptions { } diff --git a/LANCommander.Launcher.Services/CommandLineService.cs b/LANCommander.Launcher.Services/CommandLineService.cs index 76b91717..3d734ed5 100644 --- a/LANCommander.Launcher.Services/CommandLineService.cs +++ b/LANCommander.Launcher.Services/CommandLineService.cs @@ -45,6 +45,7 @@ namespace LANCommander.Launcher.Services await result.WithParsedAsync(RunScript); await result.WithParsedAsync(Install); await result.WithParsedAsync(Uninstall); + await result.WithParsedAsync(Run); await result.WithParsedAsync(Sync); await result.WithParsedAsync(Import); await result.WithParsedAsync(Login); @@ -121,6 +122,22 @@ namespace LANCommander.Launcher.Services } } + private async Task Run(RunCommandLineOptions options) + { + Console.WriteLine($"Running game with ID {options.GameId}..."); + + try + { + var game = await GameService.Get(options.GameId); + + await GameService.Run(game, options.ActionId); + } + catch (Exception ex) + { + Console.WriteLine($"Game could not run: {ex.Message}"); + } + } + private async Task Sync(SyncCommandLineOptions options) { Console.WriteLine("Syncing games from server...");