Add CLI verb to install game

This commit is contained in:
Pat Hartl 2024-08-07 01:14:29 -05:00
parent 3925ec4c34
commit beecf0beee
2 changed files with 33 additions and 1 deletions

View file

@ -27,6 +27,13 @@ namespace LANCommander.Launcher.Models
public string NewKey { get; set; }
}
[Verb("Install", HelpText = "Install a game from the server")]
public class InstallCommandLineOptions
{
[Option("GameId", HelpText = "The GUID of the game to install")]
public Guid GameId { get; set; }
}
[Verb("Import", HelpText = "Import library items from the server")]
public class ImportCommandLineOptions { }

View file

@ -270,7 +270,14 @@ namespace LANCommander.Launcher
await client.ValidateTokenAsync();
var result = CommandLine.Parser.Default.ParseArguments<RunScriptCommandLineOptions, ImportCommandLineOptions>(args);
var result = CommandLine.Parser.Default.ParseArguments
<
RunScriptCommandLineOptions,
InstallCommandLineOptions,
ImportCommandLineOptions,
LoginCommandLineOptions,
LogoutCommandLineOptions
>(args);
await result.WithParsedAsync<RunScriptCommandLineOptions>(async (options) =>
{
@ -304,6 +311,24 @@ namespace LANCommander.Launcher
}
});
await result.WithParsedAsync<InstallCommandLineOptions>(async (options) =>
{
var client = scope.ServiceProvider.GetService<SDK.Client>();
Console.WriteLine($"Downloading and installing game with ID {options.GameId}...");
try
{
var installDirectory = await client.Games.InstallAsync(options.GameId);
Console.WriteLine($"Game successfully installed to {installDirectory}");
}
catch (Exception ex)
{
Console.WriteLine($"Game could not be installed: {ex.Message}");
}
});
await result.WithParsedAsync<ImportCommandLineOptions>(async (options) =>
{
var importService = scope.ServiceProvider.GetService<ImportService>();