Add CLI verbs for running scripts and importing games
This commit is contained in:
parent
7c73b0aa1a
commit
ce32bc8137
2 changed files with 72 additions and 6 deletions
|
|
@ -19,5 +19,17 @@ namespace LANCommander.Launcher.Models
|
|||
|
||||
[Option("Type", HelpText = "The type of script to run")]
|
||||
public ScriptType Type { get; set; }
|
||||
|
||||
[Option("NewName", HelpText = "The new name to use in a name change script")]
|
||||
public string NewName { get; set; }
|
||||
|
||||
[Option("NewKey", HelpText = "The new key to use in a key change script")]
|
||||
public string NewKey { get; set; }
|
||||
}
|
||||
|
||||
[Verb("Import", HelpText = "Import library items from the server")]
|
||||
public class ImportCommandLineOptions
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace LANCommander.Launcher
|
|||
static Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
Logger?.Debug("Starting up launcher...");
|
||||
Logger?.Debug("Loading settings from file");
|
||||
|
|
@ -243,7 +243,7 @@ namespace LANCommander.Launcher
|
|||
|
||||
if (args.Length > 0)
|
||||
{
|
||||
ParseCommandLine(args);
|
||||
await ParseCommandLineAsync(args, app);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -261,13 +261,67 @@ namespace LANCommander.Launcher
|
|||
}
|
||||
}
|
||||
|
||||
static void ParseCommandLine(string[] args)
|
||||
static async Task ParseCommandLineAsync(string[] args, PhotinoBlazorApp app)
|
||||
{
|
||||
var result = CommandLine.Parser.Default.ParseArguments<RunScriptCommandLineOptions>(args)
|
||||
.WithParsed<RunScriptCommandLineOptions>(options =>
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var client = scope.ServiceProvider.GetService<SDK.Client>();
|
||||
|
||||
await client.ValidateTokenAsync();
|
||||
|
||||
var result = CommandLine.Parser.Default.ParseArguments<RunScriptCommandLineOptions, ImportCommandLineOptions>(args);
|
||||
|
||||
await result.WithParsedAsync<RunScriptCommandLineOptions>(async (options) =>
|
||||
{
|
||||
|
||||
var client = scope.ServiceProvider.GetService<SDK.Client>();
|
||||
|
||||
switch (options.Type)
|
||||
{
|
||||
case SDK.Enums.ScriptType.Install:
|
||||
await client.Scripts.RunInstallScriptAsync(options.InstallDirectory, options.GameId);
|
||||
break;
|
||||
|
||||
case SDK.Enums.ScriptType.Uninstall:
|
||||
await client.Scripts.RunUninstallScriptAsync(options.InstallDirectory, options.GameId);
|
||||
break;
|
||||
|
||||
case SDK.Enums.ScriptType.BeforeStart:
|
||||
await client.Scripts.RunBeforeStartScriptAsync(options.InstallDirectory, options.GameId);
|
||||
break;
|
||||
|
||||
case SDK.Enums.ScriptType.AfterStop:
|
||||
await client.Scripts.RunAfterStopScriptAsync(options.InstallDirectory, options.GameId);
|
||||
break;
|
||||
|
||||
case SDK.Enums.ScriptType.NameChange:
|
||||
await client.Scripts.RunNameChangeScriptAsync(options.InstallDirectory, options.GameId, options.NewName);
|
||||
break;
|
||||
|
||||
case SDK.Enums.ScriptType.KeyChange:
|
||||
await client.Scripts.RunKeyChangeScriptAsync(options.InstallDirectory, options.GameId, options.NewKey);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
await result.WithParsedAsync<ImportCommandLineOptions>(async (options) =>
|
||||
{
|
||||
var importService = scope.ServiceProvider.GetService<ImportService>();
|
||||
|
||||
Console.WriteLine("Importing games from server...");
|
||||
|
||||
importService.OnImportComplete += async () =>
|
||||
{
|
||||
Console.WriteLine("Import complete!");
|
||||
};
|
||||
|
||||
importService.OnImportFailed += async () =>
|
||||
{
|
||||
Console.WriteLine("Import failed!");
|
||||
};
|
||||
|
||||
await importService.ImportAsync();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue