about summary refs log tree commit diff
path: root/MatrixUtils.RoomUpgradeCLI/Commands/ExecuteCommand.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-08-12 16:47:27 +0200
committerRory& <root@rory.gay>2025-08-12 16:47:56 +0200
commitb0581cd4b13e32a0a802ba8ddfcb6daad137cc49 (patch)
treefc7ea1edbab44880c24d60adb508f2f04992f4e8 /MatrixUtils.RoomUpgradeCLI/Commands/ExecuteCommand.cs
parentExample config (diff)
downloadMatrixUtils-b0581cd4b13e32a0a802ba8ddfcb6daad137cc49.tar.xz
Room upgrade CLI changes
Diffstat (limited to 'MatrixUtils.RoomUpgradeCLI/Commands/ExecuteCommand.cs')
-rw-r--r--MatrixUtils.RoomUpgradeCLI/Commands/ExecuteCommand.cs39
1 files changed, 39 insertions, 0 deletions
diff --git a/MatrixUtils.RoomUpgradeCLI/Commands/ExecuteCommand.cs b/MatrixUtils.RoomUpgradeCLI/Commands/ExecuteCommand.cs
new file mode 100644

index 0000000..5815a35 --- /dev/null +++ b/MatrixUtils.RoomUpgradeCLI/Commands/ExecuteCommand.cs
@@ -0,0 +1,39 @@ +using System.Text.Json; +using System.Text.Json.Nodes; +using ArcaneLibs.Extensions; +using LibMatrix.Helpers; +using LibMatrix.Homeservers; + +namespace MatrixUtils.RoomUpgradeCLI.Commands; + +public class ExecuteCommand(ILogger<ExecuteCommand> logger, IHost host, RuntimeContext ctx, AuthenticatedHomeserverGeneric hs) : IHostedService { + public async Task StartAsync(CancellationToken cancellationToken) { + if (ctx.Args.Length <= 1) { + await PrintHelp(); + return; + } + var filename = ctx.Args[1]; + if (filename.StartsWith("--")) { + Console.WriteLine("Filename cannot start with --, please provide a valid filename."); + await PrintHelp(); + } + + var rbj = await JsonSerializer.DeserializeAsync<JsonObject>(File.OpenRead(filename)); + var rb = rbj.ContainsKey(nameof(RoomUpgradeBuilder.OldRoomId)) + ? rbj.Deserialize<RoomUpgradeBuilder>() + : rbj.Deserialize<RoomBuilder>(); + Console.WriteLine($"Executing room builder file of type {rb.GetType().Name}..."); + await rb!.Create(hs); + + await host.StopAsync(cancellationToken); + } + + public async Task StopAsync(CancellationToken cancellationToken) { } + + private async Task PrintHelp() { + Console.WriteLine("Usage: execute [filename]"); + Console.WriteLine("Options:"); + Console.WriteLine(" --help Show this help message"); + await host.StopAsync(); + } +} \ No newline at end of file